#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
bool debug = 1;
int last = 0, C = 1;
bool ask(ll x) {
assert(1 <= x && x <= n);
bool res;
cout << "? " << x << endl;
if (debug) {
if (abs(last - x) >= C)
res = 1;
else
res = 0;
last = x;
cout << res << endl;
}
else
cin >> res;
return res;
}
int main() {
cin >> n;
// finding the starting position
ll L = 1, R = n, x = 0, dir = 0;
ll minv = 0, maxv = 0;
while (L < R) {
ll M = (L + R) / 2;
if (dir == 0) {
x += M;
maxv = max(maxv, x);
}
else {
x -= M;
minv = min(minv, x);
}
dir = 1 - dir;
L = M + 1;
}
assert(maxv - minv <= n - 1);
L = 1; R = n; x = 1 - minv; dir = 0;
ask(x);
while (L < R) {
ll M = (L + R) / 2;
bool r;
if (dir == 0) {
r = ask(x + M);
x += M;
}
else {
r = ask(x - M);
x -= M;
}
dir = 1 - dir;
if (r)
R = M;
else
L = M + 1;
}
cout << "= " << L << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Token parameter [name=cmd] equals to "1", doesn't correspond to pattern "[?=]" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Token parameter [name=cmd] equals to "1", doesn't correspond to pattern "[?=]" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Token parameter [name=cmd] equals to "1", doesn't correspond to pattern "[?=]" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Token parameter [name=cmd] equals to "1", doesn't correspond to pattern "[?=]" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Token parameter [name=cmd] equals to "1", doesn't correspond to pattern "[?=]" |
2 |
Halted |
0 ms |
0 KB |
- |