#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int n;
bool ask (int l, int r) {
assert(1 <= l && l <= r && r <= n);
cout << "? " << l << " " << r << "\n";
cout.flush();
bool ans; cin >> ans;
return ans;
}
void answer (int ans) {
cout << "! " << ans << "\n";
cout.flush();
}
bool okOdd (int sz, int mid) {
return mid - sz / 2 >= 1 && mid + sz / 2 <= n;
}
bool okEven (int sz, int mid) {
return mid - sz / 2 + 1 >= 1 && mid + sz / 2 <= n;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int bestOdd = 1, bestEven = 0;
for (int i = 1; i <= n; i++) {
while (okOdd(bestOdd + 2, i) && ask(i - bestOdd / 2 - 1, i + bestOdd / 2 + 1)) bestOdd += 2;
if (i < n) {
while (okEven(bestEven + 2, i) && ask(i - bestEven / 2, i + bestEven / 2 + 1)) bestEven += 2;
}
}
answer(max(bestOdd, bestEven));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
336 KB |
Output is correct |
2 |
Correct |
109 ms |
336 KB |
Output is correct |
3 |
Correct |
115 ms |
336 KB |
Output is correct |
4 |
Correct |
107 ms |
336 KB |
Output is correct |
5 |
Correct |
106 ms |
336 KB |
Output is correct |
6 |
Correct |
99 ms |
336 KB |
Output is correct |
7 |
Correct |
111 ms |
336 KB |
Output is correct |
8 |
Correct |
104 ms |
336 KB |
Output is correct |
9 |
Correct |
107 ms |
336 KB |
Output is correct |
10 |
Correct |
105 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
336 KB |
Output is correct |
2 |
Correct |
109 ms |
336 KB |
Output is correct |
3 |
Correct |
115 ms |
336 KB |
Output is correct |
4 |
Correct |
107 ms |
336 KB |
Output is correct |
5 |
Correct |
106 ms |
336 KB |
Output is correct |
6 |
Correct |
99 ms |
336 KB |
Output is correct |
7 |
Correct |
111 ms |
336 KB |
Output is correct |
8 |
Correct |
104 ms |
336 KB |
Output is correct |
9 |
Correct |
107 ms |
336 KB |
Output is correct |
10 |
Correct |
105 ms |
336 KB |
Output is correct |
11 |
Correct |
976 ms |
336 KB |
Output is correct |
12 |
Correct |
1054 ms |
336 KB |
Output is correct |
13 |
Correct |
1020 ms |
336 KB |
Output is correct |
14 |
Correct |
997 ms |
336 KB |
Output is correct |
15 |
Correct |
1024 ms |
336 KB |
Output is correct |
16 |
Correct |
1000 ms |
336 KB |
Output is correct |
17 |
Correct |
997 ms |
336 KB |
Output is correct |
18 |
Correct |
1062 ms |
336 KB |
Output is correct |
19 |
Correct |
1014 ms |
336 KB |
Output is correct |
20 |
Correct |
981 ms |
336 KB |
Output is correct |
21 |
Correct |
995 ms |
336 KB |
Output is correct |
22 |
Correct |
1000 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1544 ms |
336 KB |
Output is correct |
2 |
Correct |
1162 ms |
336 KB |
Output is correct |
3 |
Correct |
1530 ms |
336 KB |
Output is correct |
4 |
Correct |
1556 ms |
336 KB |
Output is correct |
5 |
Correct |
1537 ms |
336 KB |
Output is correct |
6 |
Correct |
1527 ms |
336 KB |
Output is correct |
7 |
Correct |
1573 ms |
336 KB |
Output is correct |
8 |
Correct |
1604 ms |
336 KB |
Output is correct |
9 |
Correct |
1537 ms |
336 KB |
Output is correct |
10 |
Correct |
1570 ms |
336 KB |
Output is correct |
11 |
Correct |
1584 ms |
336 KB |
Output is correct |
12 |
Correct |
1560 ms |
336 KB |
Output is correct |
13 |
Correct |
1527 ms |
336 KB |
Output is correct |
14 |
Correct |
1568 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
336 KB |
Output is correct |
2 |
Correct |
109 ms |
336 KB |
Output is correct |
3 |
Correct |
115 ms |
336 KB |
Output is correct |
4 |
Correct |
107 ms |
336 KB |
Output is correct |
5 |
Correct |
106 ms |
336 KB |
Output is correct |
6 |
Correct |
99 ms |
336 KB |
Output is correct |
7 |
Correct |
111 ms |
336 KB |
Output is correct |
8 |
Correct |
104 ms |
336 KB |
Output is correct |
9 |
Correct |
107 ms |
336 KB |
Output is correct |
10 |
Correct |
105 ms |
336 KB |
Output is correct |
11 |
Correct |
976 ms |
336 KB |
Output is correct |
12 |
Correct |
1054 ms |
336 KB |
Output is correct |
13 |
Correct |
1020 ms |
336 KB |
Output is correct |
14 |
Correct |
997 ms |
336 KB |
Output is correct |
15 |
Correct |
1024 ms |
336 KB |
Output is correct |
16 |
Correct |
1000 ms |
336 KB |
Output is correct |
17 |
Correct |
997 ms |
336 KB |
Output is correct |
18 |
Correct |
1062 ms |
336 KB |
Output is correct |
19 |
Correct |
1014 ms |
336 KB |
Output is correct |
20 |
Correct |
981 ms |
336 KB |
Output is correct |
21 |
Correct |
995 ms |
336 KB |
Output is correct |
22 |
Correct |
1000 ms |
336 KB |
Output is correct |
23 |
Correct |
1544 ms |
336 KB |
Output is correct |
24 |
Correct |
1162 ms |
336 KB |
Output is correct |
25 |
Correct |
1530 ms |
336 KB |
Output is correct |
26 |
Correct |
1556 ms |
336 KB |
Output is correct |
27 |
Correct |
1537 ms |
336 KB |
Output is correct |
28 |
Correct |
1527 ms |
336 KB |
Output is correct |
29 |
Correct |
1573 ms |
336 KB |
Output is correct |
30 |
Correct |
1604 ms |
336 KB |
Output is correct |
31 |
Correct |
1537 ms |
336 KB |
Output is correct |
32 |
Correct |
1570 ms |
336 KB |
Output is correct |
33 |
Correct |
1584 ms |
336 KB |
Output is correct |
34 |
Correct |
1560 ms |
336 KB |
Output is correct |
35 |
Correct |
1527 ms |
336 KB |
Output is correct |
36 |
Correct |
1568 ms |
336 KB |
Output is correct |
37 |
Correct |
1612 ms |
336 KB |
Output is correct |
38 |
Correct |
1535 ms |
336 KB |
Output is correct |
39 |
Correct |
1562 ms |
336 KB |
Output is correct |
40 |
Correct |
1583 ms |
336 KB |
Output is correct |
41 |
Correct |
1552 ms |
336 KB |
Output is correct |
42 |
Correct |
1604 ms |
336 KB |
Output is correct |
43 |
Correct |
1608 ms |
336 KB |
Output is correct |
44 |
Correct |
1599 ms |
336 KB |
Output is correct |
45 |
Correct |
1581 ms |
336 KB |
Output is correct |
46 |
Correct |
1548 ms |
336 KB |
Output is correct |
47 |
Correct |
1554 ms |
336 KB |
Output is correct |
48 |
Correct |
1559 ms |
336 KB |
Output is correct |
49 |
Correct |
1540 ms |
336 KB |
Output is correct |
50 |
Correct |
1537 ms |
336 KB |
Output is correct |
51 |
Correct |
1550 ms |
336 KB |
Output is correct |
52 |
Correct |
1538 ms |
336 KB |
Output is correct |