답안 #557095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557095 2022-05-04T17:55:43 Z aryan12 Colors (BOI20_colors) C++17
0 / 100
2 ms 320 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
	int n;
	cin >> n;
	if(n == 2)
	{
		cout << "? 1" << endl;
		int reply;
		cin >> reply;
		cout << "? 2" << endl;
		cin >> reply;
		reply = 1 - reply;
		cout << "= " << reply + 1 << endl;
		return;
	}
	int reply;
	cout << "? " << 3 * n / 4 << endl;
	cin >> reply;
	cout << "? " << n / 4 << endl;
	cin >> reply;
	set<int> already_replied;
	already_replied.insert(3 * n / 4);
	already_replied.insert(n / 4);
	int value = (3 * n / 4) - (n / 4);
	int to_check = value;
	if(reply == 0)
	{
		to_check += (value + 1) / 2;
	}
	else
	{
		to_check -= (value + 1) / 2;
	}
	// cout << "value = " << value << ", to_check = " << to_check << endl;
	int queries = 2;
	int current_value = n / 4;
	int final_answer = (reply == 0) ? n : (3 * n / 4 - n / 4);
	while(true)
	{
		queries++;
		if(queries == 65)
		{
			break;
		}
		// cout << "current to check is: " << to_check << endl;
		int to_the_left = current_value - to_check;
		int to_the_right = current_value + to_check;
		if(already_replied.count(to_the_left) || to_the_left <= 0)
		{
			if(already_replied.count(to_the_right) || to_the_right > n)
			{
				for(int i = 1; i <= n; i++)
				{
					if(!already_replied.count(i))
					{
						cout << "? " << i << endl;
						cin >> reply;
						current_value = i;
						already_replied.insert(i);
						break;
					}
				}
			}
			else
			{
				cout << "? " << to_the_right << endl;
				already_replied.insert(to_the_right);
				cin >> reply;
				value = (value + 1) / 2;
				current_value = to_the_right;
				if(reply == 0)
				{
					to_check += value / 2;
				}
				else
				{
					final_answer = to_check;
					to_check -= value / 2;
				}
			}
		}
		else
		{
			cout << "? " << to_the_left << endl;
			already_replied.insert(to_the_left);
			cin >> reply;
			value = (value + 1) / 2;
			current_value = to_the_left;
			if(reply == 0)
			{
				to_check += value / 2;
			}
			else
			{
				final_answer = to_check;
				to_check -= value / 2;
			}
		}
	}
	cout << "= " << final_answer << endl;
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB OK (7 queries)
2 Correct 1 ms 208 KB OK (49 queries)
3 Correct 1 ms 320 KB OK (10 queries)
4 Correct 1 ms 320 KB OK (26 queries)
5 Correct 1 ms 208 KB OK (23 queries)
6 Correct 1 ms 208 KB OK (56 queries)
7 Correct 1 ms 208 KB OK (52 queries)
8 Correct 1 ms 208 KB OK (43 queries)
9 Correct 1 ms 208 KB OK (46 queries)
10 Correct 0 ms 208 KB OK (11 queries)
11 Correct 1 ms 208 KB OK (14 queries)
12 Correct 1 ms 208 KB OK (23 queries)
13 Correct 1 ms 208 KB OK (47 queries)
14 Correct 1 ms 208 KB OK (44 queries)
15 Correct 1 ms 208 KB OK (54 queries)
16 Correct 1 ms 320 KB OK (53 queries)
17 Correct 1 ms 208 KB OK (35 queries)
18 Correct 2 ms 316 KB OK (37 queries)
19 Incorrect 1 ms 208 KB Wrong guess
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB OK (7 queries)
2 Correct 1 ms 208 KB OK (49 queries)
3 Correct 1 ms 320 KB OK (10 queries)
4 Correct 1 ms 320 KB OK (26 queries)
5 Correct 1 ms 208 KB OK (23 queries)
6 Correct 1 ms 208 KB OK (56 queries)
7 Correct 1 ms 208 KB OK (52 queries)
8 Correct 1 ms 208 KB OK (43 queries)
9 Correct 1 ms 208 KB OK (46 queries)
10 Correct 0 ms 208 KB OK (11 queries)
11 Correct 1 ms 208 KB OK (14 queries)
12 Correct 1 ms 208 KB OK (23 queries)
13 Correct 1 ms 208 KB OK (47 queries)
14 Correct 1 ms 208 KB OK (44 queries)
15 Correct 1 ms 208 KB OK (54 queries)
16 Correct 1 ms 320 KB OK (53 queries)
17 Correct 1 ms 208 KB OK (35 queries)
18 Correct 2 ms 316 KB OK (37 queries)
19 Incorrect 1 ms 208 KB Wrong guess
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB OK (7 queries)
2 Correct 1 ms 208 KB OK (49 queries)
3 Correct 1 ms 320 KB OK (10 queries)
4 Correct 1 ms 320 KB OK (26 queries)
5 Correct 1 ms 208 KB OK (23 queries)
6 Correct 1 ms 208 KB OK (56 queries)
7 Correct 1 ms 208 KB OK (52 queries)
8 Correct 1 ms 208 KB OK (43 queries)
9 Correct 1 ms 208 KB OK (46 queries)
10 Correct 0 ms 208 KB OK (11 queries)
11 Correct 1 ms 208 KB OK (14 queries)
12 Correct 1 ms 208 KB OK (23 queries)
13 Correct 1 ms 208 KB OK (47 queries)
14 Correct 1 ms 208 KB OK (44 queries)
15 Correct 1 ms 208 KB OK (54 queries)
16 Correct 1 ms 320 KB OK (53 queries)
17 Correct 1 ms 208 KB OK (35 queries)
18 Correct 2 ms 316 KB OK (37 queries)
19 Incorrect 1 ms 208 KB Wrong guess
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB OK (7 queries)
2 Correct 1 ms 208 KB OK (49 queries)
3 Correct 1 ms 320 KB OK (10 queries)
4 Correct 1 ms 320 KB OK (26 queries)
5 Correct 1 ms 208 KB OK (23 queries)
6 Correct 1 ms 208 KB OK (56 queries)
7 Correct 1 ms 208 KB OK (52 queries)
8 Correct 1 ms 208 KB OK (43 queries)
9 Correct 1 ms 208 KB OK (46 queries)
10 Correct 0 ms 208 KB OK (11 queries)
11 Correct 1 ms 208 KB OK (14 queries)
12 Correct 1 ms 208 KB OK (23 queries)
13 Correct 1 ms 208 KB OK (47 queries)
14 Correct 1 ms 208 KB OK (44 queries)
15 Correct 1 ms 208 KB OK (54 queries)
16 Correct 1 ms 320 KB OK (53 queries)
17 Correct 1 ms 208 KB OK (35 queries)
18 Correct 2 ms 316 KB OK (37 queries)
19 Incorrect 1 ms 208 KB Wrong guess
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB OK (7 queries)
2 Correct 1 ms 208 KB OK (49 queries)
3 Correct 1 ms 320 KB OK (10 queries)
4 Correct 1 ms 320 KB OK (26 queries)
5 Correct 1 ms 208 KB OK (23 queries)
6 Correct 1 ms 208 KB OK (56 queries)
7 Correct 1 ms 208 KB OK (52 queries)
8 Correct 1 ms 208 KB OK (43 queries)
9 Correct 1 ms 208 KB OK (46 queries)
10 Correct 0 ms 208 KB OK (11 queries)
11 Correct 1 ms 208 KB OK (14 queries)
12 Correct 1 ms 208 KB OK (23 queries)
13 Correct 1 ms 208 KB OK (47 queries)
14 Correct 1 ms 208 KB OK (44 queries)
15 Correct 1 ms 208 KB OK (54 queries)
16 Correct 1 ms 320 KB OK (53 queries)
17 Correct 1 ms 208 KB OK (35 queries)
18 Correct 2 ms 316 KB OK (37 queries)
19 Incorrect 1 ms 208 KB Wrong guess
20 Halted 0 ms 0 KB -