#include <bits/stdc++.h>
using namespace std;
#define ll long long
set<ll> st;
ll pos = 0, ans = 1e18;
bool ask(ll n){
cout << "? " << n << endl;
st.insert(n);
int res;
cin >> res;
if(res){
ans = min(ans, abs(n-pos));
}
pos = n;
return (res == 1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ans = n;
if(n <= 64){
ll l = 1, r = n+1;
ask(1);
for(int x=1;x<n;x++){
if(x&1){
r--;
if(ask(r)){
ans = min(ans, r-l);
}
} else {
l++;
if(ask(l)){
ans = min(ans, r-l);
}
}
}
cout << "= " << ans << endl;
return 0;
}
ll left = (n%2), right = (n+1)/2-1;
while(left <= right){
ll mid = (left+right) >> 1;
ll pL = (n%2 == 0 ? n/2-mid : (n+1)/2-mid);
ll pR = (n%2 == 0 ? n/2+1+mid : (n+1)/2+mid);
ask(pL);
if(ask(pR)){
ans = min(ans, pR-pL);
right = mid-1;
} else {
left = mid+1;
}
}
ll prv = ans;
for(int i=1;i<=3;i++){
bool valid = false;
for(ll x=1;x<=n;x++){
if(prv-i <= 0) break;
if(!st.count(x) && !st.count(x+prv-i) && x+prv-i <= n){
ask(x);
if(ask(x+prv-i)){
valid = true;
}
break;
}
}
if(!valid) break;
}
cout << "= " << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong guess |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong guess |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong guess |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong guess |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Wrong guess |
2 |
Halted |
0 ms |
0 KB |
- |