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;
long long last, C;
set <long long> cont;
long long N;
int ask(long long x) {
cout << "? " << x << endl;
assert(cont.count(x) == 0);
assert(1 <= x && x <= N);
cont.insert(x);
int ans = (abs(x - last) >= C);
cin >> ans;
last = x;
return ans;
}
long long solve(long long start, long long diff, long long step) {
if(step == 1) {
ask(start);
return abs(diff);
}
long long ans;
if(step % 2 == 0) {
long long last = start + (step - 1) * diff;
long long var = solve(last, -diff * 2, step / 2);
long long check = diff > 0 ? last - var + diff : last + var + diff;
if(ask(check)) ans = var - abs(diff);
else ans = var;
if(check != start) ask(start);
} else {
long long last = start + diff;
long long var = solve(last, diff * 2, step / 2);
long long check = diff > 0 ? last + var - diff : last - var - diff;
if(ask(check)) {
ans = var - abs(diff);
ask(start);
} else if (ask(start)) {
ans = var;
} else {
ans = var + abs(diff);
}
}
return ans;
}
int main() {
C = 556;
cin >> N;
long long ans = solve(1, 1, N);
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... |