이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
bool debug = 1;
int last = 0, C = 1;
bool ask(ll x) {
assert(1 <= x && x <= n);
bool res;
cout << "? " << x << endl;
if (debug) {
if (abs(last - x) >= C)
res = 1;
else
res = 0;
last = x;
cout << res << endl;
}
else
cin >> res;
return res;
}
int main() {
cin >> n;
// finding the starting position
ll L = 1, R = n, x = 0, dir = 0;
ll minv = 0, maxv = 0;
while (L < R) {
ll M = (L + R) / 2;
if (dir == 0) {
x += M;
maxv = max(maxv, x);
}
else {
x -= M;
minv = min(minv, x);
}
dir = 1 - dir;
L = M + 1;
}
assert(maxv - minv <= n - 1);
L = 1; R = n; x = 1 - minv; dir = 0;
ask(x);
while (L < R) {
ll M = (L + R) / 2;
bool r;
if (dir == 0) {
r = ask(x + M);
x += M;
}
else {
r = ask(x - M);
x -= M;
}
dir = 1 - dir;
if (r)
R = M;
else
L = M + 1;
}
cout << "= " << L << endl;
}
# | 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... |