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 <stdio.h>
int query(long long i) {
int x;
printf("? %lld\n", i), fflush(stdout);
scanf("%d", &x);
return x;
}
int main() {
long long n, m, l, r, c;
int turn;
scanf("%lld", &n);
l = 0;
for (m = n - 1; m > 0; m /= 4)
l -= (m + 1) / 2;
l = 1 - l, r = l, m = n - 1, turn = 0;
query(r);
c = 1;
for (m = n - 1; m > 0; m /= 2, turn ^= 1)
if (turn == 0) {
if (query(l -= (m + 1) / 2))
r -= (m + 1) / 2, m--;
else
c += (m + 1) / 2;
} else {
if (query(r += (m + 1) / 2))
l += (m + 1) / 2, m--;
else
c += (m + 1) / 2;
}
printf("= %lld\n", c);
return 0;
}
Compilation message (stderr)
Colors.c: In function 'query':
Colors.c:7:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | scanf("%d", &x);
| ^~~~~~~~~~~~~~~
Colors.c: In function 'main':
Colors.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%lld", &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... |