#include <bits/stdc++.h>
using namespace std;
//#define T
typedef long long ll;
ll C, n;
int ask(ll q){
static ll bef = 0;
cout << "? " << q << endl;
int ans;
#ifdef T
if(q < 1 || q > n){
cout << "INVALID";
exit(1);
}
cout << (abs(q - bef) < C?ans=0:ans=1) << endl;
bef = q;
#else
cin >> ans;
#endif
return ans;
}
ll solve(ll n, ll c, ll add, bool dir){
if(n == 1)
return 1 + add;
ll diff = n/2 + add;
ll q = (dir)?c+diff:c-diff;
if(ask(q))
return solve(n/2, q, add, !dir);
else
return solve((n+1)/2, q, add + n/2, !dir);
}
ll start(ll N){
if(N == 1)
return 1;
return (N + 1)/2 + 1 - start((N + 1)/2);
}
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
#ifdef T
srand(time(NULL));
n = rand();
C = rand()%n + 1;
cout << n << ' ' << C << endl;
#else
cin >> n;
#endif
int c = start(n);
ask(c);
ll ans = solve(n, c, 0, c<(n+1)/2?1:0);
cout << "= " << ans;
}
Compilation message
Colors.cpp: In function 'int ask(ll)':
Colors.cpp:11:15: warning: unused variable 'bef' [-Wunused-variable]
11 | static ll bef = 0;
| ^~~
Colors.cpp: At global scope:
Colors.cpp:11:15: warning: 'bef' defined but not used [-Wunused-variable]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
10 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (6 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
17 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
18 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
19 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
21 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
22 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
10 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (6 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
17 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
18 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
19 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
21 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
22 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
10 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (6 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
17 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
18 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
19 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
21 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
22 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
10 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (6 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
17 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
18 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
19 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
21 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
22 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
10 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (6 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
17 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
18 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
19 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
21 |
Correct |
1 ms |
344 KB |
OK (7 queries) |
22 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
23 |
Halted |
0 ms |
0 KB |
- |