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 <iostream>
#include <set>
using namespace std;
#define int long long
int n, at;
set<int> s;
bool qry(int x) {
if (at + x <= n) at += x;
else at -= x;
if (s.count(at)) exit(0);
cout << "? " << at << endl;
s.insert(at);
bool ans; cin >> ans;
return ans;
}
int32_t main() {
cin >> n;
bool added = true;
int left = n;
at = 1;
for (int i = (left + 1) / 2; i > 0; left >>= 1, i = (left + 1) / 2) {
if (!added) at += i;
added = !added;
if (i == 1) break;
}
cout << "? " << at << endl;
int tmp; cin >> tmp;
s.insert(at);
int sum = 0;
left = n;
for (int i = (left + 1) / 2; i > 0; left >>= 1, i = (left + 1) / 2) {
int chg = sum + i;
if (chg >= n) continue;
if (!qry(chg)) sum = chg;
}
cout << "= " << sum + 1 << '\n';
return 0;
}
/*
49
25
12
6
3
2
1
*/
# | 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... |