#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
unordered_set<int> used;
inline int getvalid(int N) {
int mincur = 0, maxcur = 0;
int cur = 0;
int mini = 1, maxi = N-1;
bool parity = false;
while (mini <= maxi) {
int mid = (mini+maxi)>>1;
int next;
if (!parity) {
next = cur+mid;
} else {
next = cur-mid;
}
mini = mid+1;
cur = next;
parity ^= 1;
mincur = min(mincur, cur);
maxcur = max(maxcur, cur);
}
//assert(maxcur-mincur <= N-1);
return -mincur;
}
inline bool query(int x) {
assert(!used.count(x));
cout << "? " << x+1 << '\n' << flush;
assert(x >= 0 && x < N);
used.insert(x);
bool ret;
cin >> ret;
return ret;
}
signed main() {
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> N;
int cur = getvalid(N);
int mini = 1, maxi = N-1;
query(cur);
//bool parity = false;
while (mini < maxi) {
int mid = (mini+maxi)>>1;
int next;
if (cur+mid < N && !used.count(cur+mid)) {
next = cur+mid;
} else if (cur-mid >= 0 && !used.count(cur-mid)) {
next = cur-mid;
} else {
int inter = 0;
for (; used.count(inter) || used.count(inter+mid); inter++);
query(inter);
next = inter+mid;
}
if (query(next)) {
maxi = mid;
} else {
mini = mid+1;
}
cur = next;
//parity ^= 1;
}
cout << "= " << mini << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
9 |
Correct |
1 ms |
256 KB |
OK (8 queries) |
10 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
11 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
12 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
13 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
14 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
212 KB |
OK (7 queries) |
17 |
Incorrect |
0 ms |
212 KB |
Wrong guess |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
9 |
Correct |
1 ms |
256 KB |
OK (8 queries) |
10 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
11 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
12 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
13 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
14 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
212 KB |
OK (7 queries) |
17 |
Incorrect |
0 ms |
212 KB |
Wrong guess |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
9 |
Correct |
1 ms |
256 KB |
OK (8 queries) |
10 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
11 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
12 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
13 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
14 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
212 KB |
OK (7 queries) |
17 |
Incorrect |
0 ms |
212 KB |
Wrong guess |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
9 |
Correct |
1 ms |
256 KB |
OK (8 queries) |
10 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
11 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
12 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
13 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
14 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
212 KB |
OK (7 queries) |
17 |
Incorrect |
0 ms |
212 KB |
Wrong guess |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
3 |
Correct |
1 ms |
208 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
9 |
Correct |
1 ms |
256 KB |
OK (8 queries) |
10 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
11 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
12 |
Correct |
0 ms |
208 KB |
OK (5 queries) |
13 |
Correct |
0 ms |
208 KB |
OK (6 queries) |
14 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
212 KB |
OK (7 queries) |
17 |
Incorrect |
0 ms |
212 KB |
Wrong guess |
18 |
Halted |
0 ms |
0 KB |
- |