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;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
vi queries;
vi ans;
int query(int i)
{
queries.push_back(i);
cout << "? " << i << endl;
int a;
cin >> a;
ans.push_back(a);
return a;
}
void answer(int i)
{
cout << "= " << i << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
int l = 1, r = N;
while (r - l > 60)
l += 30, r -= 30;
if (r - l > 30)
l += 30;
double center = (l + r) / (double)2;
int len = r - l;
int a = 0;
query(l);
a = query(r);
while (a == 0 && len < N - 1)
{
len += 30;
int last = queries.back();
int next = last;
if (last < center)
next += len;
else
next -= len;
a = query(next);
}
if (a == 0)
answer(N);
else
{
int lowerB = max(1, len - 30);
while (a == 1 && len > lowerB)
{
len -= 1;
int last = queries.back();
int next = last;
if (last < center)
next += len;
else
next -= len;
a = query(next);
}
if (a == 0)
answer(len + 1);
else
answer(len);
}
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... |