Submission #370965

# Submission time Handle Problem Language Result Execution time Memory
370965 2021-02-25T09:44:56 Z flappybird Colors (BOI20_colors) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 101010
#define ln '\n'
#define bb ' '
#define abs(x) ((x)>0?(x):-(x))
ll query(ll x) {
	cout << '?' << bb << x << endl;
	ll ret;
	cin >> ret;
	return ret;
}
signed main() {
	ll N;
	cin >> N;
	ll l, r, mid;
	l = 0, r = N;
	ll prev = N / 2;
	query(prev);
	ll res;
	while (r - l > 1) {
		mid = (l + r + 1) >> 1;
		if (1 <= prev + mid && prev + mid <= N && 1 <= prev - mid && prev - mid <= N) {
			ll a = min(abs(prev + mid - 1), abs(prev + mid - N));
			ll b = min(abs(prev - mid - 1), abs(prev - mid - N));
			if (a < b) {
				prev += mid;
				res = query(prev);
			}
			else {
				prev -= mid;
				res = query(prev);
			}
		}
		else if (1 <= prev + mid && prev + mid <= N) {
			prev += mid;
			res = query(prev);
		}
		else if (1 <= prev - mid && prev - mid <= N) {
			prev -= mid;
			res = query(prev);
		}
		else {
			query(1);
			res = query(mid + 1);
		}
		if (res) r = mid;
		else l = mid;
	}
	cout << '=' << bb << r << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (4 queries)
2 Incorrect 1 ms 364 KB Hair color 1 was used multiple times
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (4 queries)
2 Incorrect 1 ms 364 KB Hair color 1 was used multiple times
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (4 queries)
2 Incorrect 1 ms 364 KB Hair color 1 was used multiple times
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (4 queries)
2 Incorrect 1 ms 364 KB Hair color 1 was used multiple times
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (4 queries)
2 Incorrect 1 ms 364 KB Hair color 1 was used multiple times
3 Halted 0 ms 0 KB -