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;
#ifdef DEBUG
#include "/Users/kutay/CP/templates/debug.h"
#else
#define debug(...) void(38)
#endif
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
auto ask = [&](int p) {
cout << "? " << p << endl;
int x; cin >> x;
return x;
};
function<int(int, int, int)> f = [&](int l, int r, int last) {
debug(l, r, last);
if (l == r) return l;
int mm = r - l + 1;
int lg = log2(mm);
if ((1 << lg) != mm) mm = (1 << (lg + 1));
int m = l + mm / 2 - 1;
int next = -1;
if (last + m <= n) {
next = last + m;
} else if (last - m > 0) {
next = last - m;
} else assert(false);
int ret = ask(next);
if (ret == 1) {
return f(l, m, next);
} else {
return f(m + 1, r, next);
}
};
int m = (1 + n) / 2 + (n & 1 ? 1 : 2);
ask(m);
int ans = f(1, n, m);
cout << "= " << ans << 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... |