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;
#define ll long long
set<ll> st;
bool ask(ll n){
cout << "? " << n << endl;
st.insert(n);
int res;
cin >> res;
return (res == 1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll ans = n;
ll pos = (n+1)/2;
ask(pos);
ll cur = 1;
ll left = 1, right = n-1;
while(left <= right){
ll mid = (left+right) >> 1;
while(st.count(cur)){
cur++;
}
bool valid = false;
if(pos-mid > 0 && !st.count(pos-mid)){
if(ask(pos-mid)){
valid = true;
} else {
valid = false;
}
pos -= mid;
} else if(pos+mid <= n && !st.count(pos+mid)){
if(ask(pos+mid)){
valid = true;
} else {
valid = false;
}
pos += mid;
} else {
ask(cur);
pos = cur;
if(ask(pos+mid)){
valid = true;
} else {
valid = false;
}
pos += mid;
}
if(valid){
ans = mid;
right = mid-1;
} else {
left = mid+1;
}
}
cout << "= " << ans << endl;
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... |