#include<bits/stdc++.h>
using namespace std;
signed main() {
int n;
cin >> n;
set<int>st;
int c;
if (n == 2) {
cout << "? 1" << endl; cin >> c;
cout << "? 2" << endl; cin >> c;
if (c == 1) cout << "= 2" << endl;
else cout << "= 1" << endl;
return 0;
} else if (n == 3) {
cout << "? 2" << endl; cin >> c;
cout << "? 3" << endl; cin >> c;
if (c == 1) cout << "= 1" << endl;
else {
cout << "? 1" << endl; cin >> c;
if (c == 1) cout << "= 2" << endl;
else cout << "= 3" << endl;
}
return 0;
}
int l = 2, r = n+1, t = 0, ans = n, end = 0;
//if (n == 3) r = 5;
cout << "? " << l << "\n"; st.insert(l);
cin >> c;
while (!end) {
if (t) {
l += 2;
assert(st.find(l) == st.end());
cout << "? " << l << endl; st.insert(l);
} else {
r -= 2;
assert(st.find(r) == st.end());
cout << "? " << r << endl; st.insert(r);
}
cin >> c;
if (c == 0) break;
else {
ans = min(ans, r - l);
if (ans <= 2) break;
}
t ^= 1;
}
if (c == 1) {
if (ans == 2) {
if (t) {
assert(st.find(r-1) == st.end());
cout << "? " << r-1 << endl;
} else {
assert(st.find(l+1) == st.end());
cout << "? " << l+1 << endl;
}
cin >> c;
if (c) ans = 1;
}
cout << "= " << ans << endl;
return 0;
}
while (c == 0) {
if (t) {
r++;
assert(st.find(r) == st.end());
cout << "? " << r << endl; st.insert(r);
} else {
l--;
assert(st.find(l) == st.end());
cout << "? " << l << endl; st.insert(l);
}
t ^= 1;
cin >> c;
if (c == 1) {
ans = min(ans, r - l);
end = 1;
}
if (c == 0 && (r - l == ans-1)) {
end = 1;
break;
}
}
cout << "= " << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (13 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (8 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (14 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (10 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
10 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (3 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (9 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (18 queries) |
17 |
Correct |
0 ms |
384 KB |
OK (4 queries) |
18 |
Correct |
1 ms |
344 KB |
OK (9 queries) |
19 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (17 queries) |
21 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
22 |
Incorrect |
0 ms |
344 KB |
Wrong guess |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (13 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (8 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (14 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (10 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
10 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (3 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (9 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (18 queries) |
17 |
Correct |
0 ms |
384 KB |
OK (4 queries) |
18 |
Correct |
1 ms |
344 KB |
OK (9 queries) |
19 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (17 queries) |
21 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
22 |
Incorrect |
0 ms |
344 KB |
Wrong guess |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (13 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (8 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (14 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (10 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
10 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (3 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (9 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (18 queries) |
17 |
Correct |
0 ms |
384 KB |
OK (4 queries) |
18 |
Correct |
1 ms |
344 KB |
OK (9 queries) |
19 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (17 queries) |
21 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
22 |
Incorrect |
0 ms |
344 KB |
Wrong guess |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (13 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (8 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (14 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (10 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
10 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (3 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (9 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (18 queries) |
17 |
Correct |
0 ms |
384 KB |
OK (4 queries) |
18 |
Correct |
1 ms |
344 KB |
OK (9 queries) |
19 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (17 queries) |
21 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
22 |
Incorrect |
0 ms |
344 KB |
Wrong guess |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
344 KB |
OK (4 queries) |
3 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
4 |
Correct |
0 ms |
344 KB |
OK (13 queries) |
5 |
Correct |
0 ms |
344 KB |
OK (8 queries) |
6 |
Correct |
0 ms |
344 KB |
OK (14 queries) |
7 |
Correct |
0 ms |
344 KB |
OK (10 queries) |
8 |
Correct |
0 ms |
344 KB |
OK (5 queries) |
9 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
10 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
11 |
Correct |
0 ms |
344 KB |
OK (3 queries) |
12 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
13 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
14 |
Correct |
0 ms |
344 KB |
OK (9 queries) |
15 |
Correct |
0 ms |
344 KB |
OK (7 queries) |
16 |
Correct |
1 ms |
344 KB |
OK (18 queries) |
17 |
Correct |
0 ms |
384 KB |
OK (4 queries) |
18 |
Correct |
1 ms |
344 KB |
OK (9 queries) |
19 |
Correct |
1 ms |
344 KB |
OK (4 queries) |
20 |
Correct |
0 ms |
344 KB |
OK (17 queries) |
21 |
Correct |
0 ms |
344 KB |
OK (6 queries) |
22 |
Incorrect |
0 ms |
344 KB |
Wrong guess |
23 |
Halted |
0 ms |
0 KB |
- |