# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
357712 | mjhmjh1104 | Colors (BOI20_colors) | C++14 | 0 ms | 0 KiB |
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 <cstdio>
#include <vector>
using namespace std;
vector<int> v;
int n, t;
int main() {
scanf("%d", &n);
int curr = 1;
int l = n / 2, r = n - 1;
while (l < r) {
v.push_back(l);
l = (l + r) / 2 + 1;
}
v.push_back(l);
reverse(v.begin(), v.end());
for (auto &i: v) {
if (curr + i <= n) curr += i;
else curr -= i;
}
printf("? %d\n", curr);
fflush(stdout);
scanf("%*d");
l = 0, r = n - 1;
while (l < r) {
int m = (l + r) / 2;
if (curr + m <= n) curr += m;
else curr -= m;
printf("? %d\n", curr);
fflush(stdout);
scanf("%d", &t);
if (t) r = m;
else l = m + 1;
}
if (l == n - 1) {
printf("? %d\n", n);
fflush(stdout);
scanf("%d", &t);
if (t) printf("= %d\n", n - 1);
else printf("= %d\n", n);
} else printf("= %d\n", l);
fflush(stdout);
}