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;
long long n,maxi,i;
int query (int x){
int ans;
cout<<"? "<<x<<endl;
cin>>ans;
return ans;
}
void answer (int x){
cout<<"= "<<x<<endl;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
for (maxi=0;;maxi++)
if ((1LL<<maxi) > n)
break;
maxi--;
long long sum = 0, sum2 = 0;
for (i=maxi;i>=0;i-=2)
sum += (1LL<<i);
for (i=maxi-1;i>=0;i-=2)
sum2 += (1LL<<i);
long long x = n - sum, c = 0;
query (x);
for (i=maxi;i>=0;i--){
if ((maxi - i) % 2){ /// ma duc in stanga
int ans = query (x - c - (1LL<<i));
x -= c + (1LL<<i);
if (!ans)
c += (1LL<<i);
} else { /// ma duc in dreapta
int ans = query (x + c + (1LL<<i));
x += c + (1LL<<i);
if (!ans)
c += (1L<<i);
}
}
answer(c+1);
return 0;
}
# | 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... |