#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
unordered_set<int> used;
bool isvalid(int cur) {
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;
}
if (next < 0 || next >= N) return false;
mini = mid+1;
cur = next;
parity ^= 1;
}
return true;
}
inline bool query(int x) {
used.insert(x);
cout << "? " << x+1 << '\n' << flush;
assert(x >= 0 && x < N);
bool ret;
cin >> ret;
return ret;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> N;
int mini = 1, maxi = N-1;
int cur = max(N/3-10, 0ll);
for (; !isvalid(cur); cur++);
query(cur);
bool parity = false;
while (mini <= maxi) {
int mid = (mini+maxi)>>1;
int next;
if (!parity) {
next = cur+mid;
} else {
next = cur-mid;
}
if (query(next)) {
maxi = mid;
} else {
mini = mid+1;
}
cur = next;
parity ^= 1;
}
cout << "= " << mini << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2386 ms |
208 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2386 ms |
208 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2386 ms |
208 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2386 ms |
208 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2386 ms |
208 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |