이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |