This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int LG=59;
inline int ask(int x){
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
ll n;
cin >> n;
ll pos=1,dir=1,st=1,step=0;
for(ll i=1LL<<LG;i>0;i>>=1){
if(step+i>n-1)continue;
step+=i;
pos+=dir*step;
if(pos>n){
ll dif=pos-n;
pos-=dif,st-=dif;
}
if(pos<1){
ll dif=1-pos;
pos+=dif,st+=dif;
}
dir=-dir;
}
ll ans=1;
ask(st);
dir=1,step=0;
for(ll i=1LL<<LG;i>0;i>>=1){
if(step+i>n-1)continue;
st+=dir*i;
if(!ask(st)){
ans+=i;
step+=i;
}
dir=-dir;
}
cout << "= " << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |