#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
ll logll(ll x) {
for (ll logx = 0; ; (x >>= 1) && (logx++)) if (x == 0) return logx;
}
bool ask(ll p) {
cout << "? " << p << endl;
bool answ;
cin >> answ;
return answ;
}
ll N;
ll lower = 0;
ll upper;
ll P;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
upper = 2 << logll(N - 1);
P = (N + 2) / 3;
ask(P);
while ((lower + 1 < upper) && (lower < N - 1)) {
ll mid = (upper + lower) / 2;
if (2 * P > N) P -= mid;
else P += mid;
if (ask(P)) {
upper = mid;
} else {
lower = mid;
}
}
cout << "= " << min<ll>(N, upper) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
OK (4 queries) |
2 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |