Submission #492697

# Submission time Handle Problem Language Result Execution time Memory
492697 2021-12-08T12:40:35 Z zhougz Colors (BOI20_colors) C++17
0 / 100
0 ms 200 KB
/**
 *    author: chowgz
 *    created: 13/04/2021 20:13:22
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	while (tt--) {
		long long n;
		cin >> n;
		long long l = 1, r = n - 1, m;
		stack<long long> s;
		while (m != n - 1) {
			m = (l + r) / 2;
			s.push(m);
			l = m + 1;
		}
		long long cur = n;
		bool up = false;
		while (!s.empty()) {
			cur += up ? s.top() : -s.top();
			up = !up;
			s.pop();
		}
		bool yes;
		auto ask = [&](long long x) {
			cur += up ? x : -x;
			up = !up;
			cout << "? " << cur << endl;
			cin >> yes;
		};
		cout << "? " << cur << endl;
		cin >> yes;
		l = 1;
		r = n - 1;
		m = (l + r) / 2;
		long long ans = n;
		while (l <= r) {
			ask(m);
			if (yes) {
				ans = m;
				r = m - 1;
			} else {
				l = m + 1;
			}
			m = (l + r) / 2;
		}
		cout << "= " << ans << endl;
	}
	return 0;
}

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:19:12: warning: 'm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |   while (m != n - 1) {
      |          ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 200 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 200 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 200 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 200 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 200 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -