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, a, b, m, prv, ans;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
prv=1;
cout<<"? "<<prv<<endl;
cin>>ans;
a=1;b=n;
while(a<b)
{
m=(a+b)/2;
if(prv-m<1&&prv+m>n)
{
cout<<"? 1"<<endl;
cin>>ans;
prv=1;
}
if(prv-m>=1)
{
prv-=m;
cout<<"? "<<prv<<endl;
cin>>ans;
if(ans==1)b=m;
else a=m+1;
}
else
{
prv+=m;
cout<<"? "<<prv<<endl;
cin>>ans;
if(ans==1)b=m;
else a=m+1;
}
}
cout<<"= "<<a<<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... |