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 int long long
int n;
int getx()
{
int st = 0, pas = 1ll << 60;
while (pas != 0)
{
if (st + pas <= n)
{
int x = st + pas;
bool oops = false;
int l = 1, r = n, pass = -1;
while (l < r)
{
int y;
pass++;
int rn = (r - l - 1) / 2;
if (pass % 2 == 0)
y = x + l + rn;
else
y = x - l - rn;
if (y > n)
oops = true;
l = abs(x - y) + 1;
x = y;
}
if (!oops)
st += pas;
}
pas /= 2;
}
return st;
}
signed main()
{
cin >> n;
int x = getx();
cout << "? " << x << endl;
int rsp;
cin >> rsp;
int l = 1, r = n;
int pas = -1;
while (l < r)
{
int y;
pas++;
///eu legit caut binar cu l si r, in ce hal am ajuns
int rn = (r - l - 1) / 2;
if (pas % 2 == 0)
y = x + l + rn;
else
y = x - l - rn;
y = max(y, 0ll);
y = min(y, n);
cout << "? " << y << endl;
if (y <= 0)
assert(false);
if (y > n)
while(true);
cin >> rsp;
if (rsp == 0)
l = abs(x - y) + 1;
else
r = abs(x - y);
x = y;
}
cout << "= " << l << 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... |