#include<iostream>
#include<vector>
#include<cassert>
#define ll long long
using namespace std;
bool ask(ll num){
cout<<"? "<<num<<endl;
bool ans;
cin>>ans;
return ans;
}
int main(){
ll n;
cin>>n;
//assert(n!=17);
if(n==1){
cout<<"= 1"<<endl;
return 0;
}
if(n==2){
bool flag=ask(1);
flag=ask(2);
if(flag) cout<<"= 1"<<endl;
else cout<<"= 2"<<endl;
return 0;
}
ll L=0,R=0,last=(1+n)/2;
bool now=1;
while(last>1){
//cout<<last;
if(now) L+=last-(1+last)/2;
else R+=last-(1+last)/2;
now=!now;
last=(1+last)/2;
}
now=1;
L++;
R=n-R;
ll l=1,r=n;
bool ans=ask(L);
ans=ask(R);
last=R-L;
if(ans) r=R-L;
else l=R-L+1;
while(l<r){
int mid=(l+r)>>1;
if(mid>last){
if(now){
L-=mid-last;
ans=ask(L);
}
else{
R+=mid-last;
ans=ask(R);
}
}
else{
if(now){
L+=last-mid;
ans=ask(L);
}
else{
R-=last-mid;
ans=ask(R);
}
}
now=!now;
last=mid;
if(ans) r=mid;
else l=mid+1;
}
cout<<"= "<<l<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Runtime error |
0 ms |
436 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Runtime error |
0 ms |
436 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Runtime error |
0 ms |
436 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Runtime error |
0 ms |
436 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Runtime error |
0 ms |
436 KB |
Execution killed with signal 13 |
9 |
Halted |
0 ms |
0 KB |
- |