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;
bool query (int Q) {
cout << "? " << Q << endl;
int x; cin >> x;
return x == 1;
}
int gen_start (int N) {
// suppose N = C
int a = 0; // a < C <= b
int b = N;
int pos = 0;
int mpos = 0;
bool f = false;
while (b - a > 1) {
int c = (a + b) >> 1;
a = c;
if (f) pos -= c;
else pos += c;
mpos = min(mpos, pos);
f = !f;
}
return mpos;
}
int main () {
int N;
cin >> N;
int mpos = - gen_start(N) + 1;
query(mpos);
int a = 0; // a < C <= b
int b = N;
bool delUp = true;
int pos = mpos;
while (b - a > 1) {
int t = (a + b) >> 1;
if (delUp) pos += t;
else pos -= t;
delUp = !delUp;
if (query(pos)) a = t;
else b = t;
}
cout << "= " << b << "\n";
}
# | 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... |