BLITZ3_2 - Editorial

PROBLEM LINK:

Practice
Contest: Division 3
Contest: Division 2
Contest: Division 1

Author: Daanish Mahajan
Tester: Istvan Nagy
Editorialist: Vichitr Gandas

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Given each Chess player has a starting time of 3 minute and after each move, 2 seconds are added to the person’s clock.

After N moves, the game ends, and the clocks of the two players have A and B seconds left. Find the total duration of the game.

Note: One move is counted as a move by a single player.

EXPLANATION:

Each player has starting time of 3 minutes or 180 seconds and there are total of N moves in the game. In each move, 2 seconds is added to the respective player’s clock. Hence the two players get a total of N∗2 seconds added to their clocks. So the total time available for the two players in total is 180+180+N∗2=360+N∗2 seconds.

We are also given the time remaining for each player which is A and B seconds respectively. So among the 360+N∗2 seconds available, A + B seconds have not been used in the game. Hence total duration of game was 360+N∗2 - (A + B) seconds.

TIME COMPLEXITY:

O(1) per test case

SOLUTIONS:

Setter's Solution
#include<bits/stdc++.h>
# define pb push_back 
#define pii pair<int, int>
#define mp make_pair
# define ll long long int

using namespace std;
  
const int maxt = 1e5;
const string newln = "\n", space = " ";
int main()
{   
    int t, n, A, B; cin >> t; 
    while(t--){
        cin >> n;
        int tot = 360 + 2 * n;
        cin >> A >> B;
        if(n % 2)assert(A >= 2);
        else assert(B >= 2);
        int ans = tot - A - B;
        cout << ans << endl;            
    }
} 
Tester's Solution
#include <iostream>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <random>

#ifdef HOME
	#include <windows.h>
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

long long readInt(long long l, long long r, char endd) {
	long long x = 0;
	int cnt = 0;
	int fi = -1;
	bool is_neg = false;
	while (true) {
		char g = getchar();
		if (g == '-') {
			assert(fi == -1);
			is_neg = true;
			continue;
		}
		if ('0' <= g && g <= '9') {
			x *= 10;
			x += g - '0';
			if (cnt == 0) {
				fi = g - '0';
			}
			cnt++;
			assert(fi != 0 || cnt == 1);
			assert(fi != 0 || is_neg == false);

			assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
		}
		else if (g == endd) {
			assert(cnt > 0);
			if (is_neg) {
				x = -x;
			}
			assert(l <= x && x <= r);
			return x;
		}
		else {
			//assert(false);
		}
	}
}

string readString(int l, int r, char endd) {
	string ret = "";
	int cnt = 0;
	while (true) {
		char g = getchar();
		assert(g != -1);
		if (g == endd) {
			break;
		}
		cnt++;
		ret += g;
	}
	assert(l <= cnt && cnt <= r);
	return ret;
}
long long readIntSp(long long l, long long r) {
	return readInt(l, r, ' ');
}
long long readIntLn(long long l, long long r) {
	return readInt(l, r, '\n');
}
string readStringLn(int l, int r) {
	return readString(l, r, '\n');
}
string readStringSp(int l, int r) {
	return readString(l, r, ' ');
}


int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	int T = readIntLn(1, 100'000);
	forn(tc, T)
	{
		int N = readIntSp(10, 100);
		int A = readIntSp(0, 180+2*((N+1)/2));
		int B = readIntLn(0, 180 + 2 * (N / 2));
		assert(A + B > 0);
		if (N & 1)
			assert(A >= 2);
		else
			assert(B >= 2);
		int sum = 2 * (180 + N);
		int res = sum - A - B;
		printf("%d\n", res);
	}
	assert(getchar() == -1);
	return 0;
}

Editorialist's Solution
/*
 * @author: vichitr
 * @date: 26th June 2021
 */

#include <bits/stdc++.h>
using namespace std;

void solve() {
	int n, a, b;
	cin >> n >> a >> b;

	int totalTime = 180 + 180 + n * 2;
	int duration = totalTime - a - b;
	cout << duration << '\n';
}


int main() {

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

VIDEO EDITORIAL:

If you have other approaches or solutions, let’s discuss in comments.

SIr, how we got to know that for each move, the person has 2 sec. ???
I mean to say that, why a person takes 2 sec. to make a move as you wrote in the editorial.
"Each player has starting time of 3 minutes or 180 seconds and there are total of N moves in the game. Each move takes 2 seconds. Hence the players spent N*2 seconds time on the moves.

Hey, there were some problem with the assumptions in the previous editorial. The editorial has been updated now. Please read the editorial again and ask us your doubts if you still have any.

Thank you sir, I got my point.

1 Like