#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ask (int x) {
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
int ind = N;
int lo = 1, hi = N;
while (lo < hi) {
int mid = (lo + hi) >> 1;
// cout << lo << " " << mid << " " << hi << " " << ind << "\n";
if (ind - mid >= 1) {
if (ask (ind - mid) == 1) {
hi = mid;
} else {
lo = mid + 1;
}
ind = ind - mid;
} else if (ind + mid <= N) {
if (ask (ind + mid) == 1) {
hi = mid;
} else {
lo = mid + 1;
}
ind = ind + mid;
} else {
if (ind - 1 >= N - ind) {
if (ask(1) == 1) {
hi = ind - 1;
} else {
lo = ind;
}
ind = 1;
} else {
if (ask(N) == 1) {
hi = N - ind;
} else {
lo = N - ind + 1;
}
ind = N;
}
}
}
cout << "= " << hi << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
OK (2 queries) |
2 |
Incorrect |
1 ms |
336 KB |
Wrong guess |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
OK (2 queries) |
2 |
Incorrect |
1 ms |
336 KB |
Wrong guess |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
OK (2 queries) |
2 |
Incorrect |
1 ms |
336 KB |
Wrong guess |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
OK (2 queries) |
2 |
Incorrect |
1 ms |
336 KB |
Wrong guess |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
OK (2 queries) |
2 |
Incorrect |
1 ms |
336 KB |
Wrong guess |
3 |
Halted |
0 ms |
0 KB |
- |