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;
int n,j;
pair<int,int> p[200001];
void prec()
{
int i=1;
int l=1,r=n;
while(l<r)
{
p[i]={l,r};
if(l==n-r+1)l++;
else r--;
if(r-l+1==n/2)j=i;
if(i%2==0)swap(p[i].first,p[i].second);
i++;
}
}
void solve()
{
int i=j;
cout<<"? "<<p[i].first<<endl;
cout.flush();
int x;
cin>>x;
cout<<"? "<<p[i].second<<endl;
cout.flush();
cin>>x;
int curr=p[i].second;
int d=abs(p[i].second-p[i].first);
int h=n/2+n%2;
if(x==1)
{
while(x==1)
{
d--;
if(d==0)
{
cout<<"= "<<1<<endl;
return;
}
int nxt=curr+d;
if(curr>h)nxt=curr-d;
cout<<"? "<<nxt<<endl;
curr=nxt;
cout.flush();
cin>>x;
}
cout<<"= "<<d<<endl;
cout.flush();
}
else
{
while(x==0)
{
d++;
if(d==n)
{
cout<<"= "<<d<<endl;
return;
}
int nxt=curr+d;
if(curr>h)nxt=curr-d;
cout<<"? "<<nxt<<endl;
cout.flush();
curr=nxt;
cin>>x;
}
cout<<"= "<<d<<endl;
cout.flush();
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
prec();
solve();
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... |