#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> ask(int i);
vector<int> res[200005];
int ans;
int big, nn;
set<int> lol;
vector<int> query(int i){
if(i == 0)
return vector<int>({0, big});
if(i == nn + 1)
return vector<int>({big, 0});
return ask(i - 1);
}
void find(int l, int r){
if(ans) return;
if(res[l][0] == res[r][0]) return;
auto it = lol.find(l);
while(res[l][0] == res[*it][0]){
l = *it;
it++;
}
it = lol.find(r);
while(res[l][0] == res[*it][0]){
l = *it;
it--;
}
int ll, rr, m = (l + r) >> 1;
res[m] = query(m);
if(res[m][0] + res[m][1] == big){
lol.insert(m);
find(l, m);
find(m, r);
return;
}
if(res[m][0] + res[m][1] == 0){
ans = m;
return;
}
for(rr = m + 1; rr < r; rr++){
res[rr] = query(rr);
if(res[rr][0] + res[rr][1] == big){
lol.insert(rr);
find(rr, r);
break;
}
if(res[rr][0] + res[rr][1] == 0){
ans = rr;
return;
}
}
for(ll = m - 1; ll > l; ll--){
res[ll] = query(ll);
if(res[ll][0] + res[ll][1] == big){
lol.insert(ll);
find(l, ll);
break;
}
if(res[ll][0] + res[ll][1] == 0){
ans = ll;
return;
}
}
}
int find_best(int n) {
nn = n;
for(int i = 0; i < 3; i++) {
vector<int> res = ask(i);
if(res[0] + res[1] == 0)
return i;
big = max(big, res[0] + res[1]);
}
res[0] = query(0);
res[nn + 1] = query(nn + 1);
lol.insert(0);
lol.insert(nn + 1);
find(0, nn + 1);
return ans - 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5040 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
5040 KB |
Output is correct |
8 |
Correct |
5 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
4992 KB |
Output is correct |
10 |
Correct |
5 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
6 ms |
5092 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
5020 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5116 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
8 ms |
5112 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
8 ms |
5140 KB |
Output is correct |
14 |
Correct |
8 ms |
4992 KB |
Output is correct |
15 |
Correct |
13 ms |
4992 KB |
Output is correct |
16 |
Correct |
45 ms |
5352 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
41 ms |
5332 KB |
Output is correct |
19 |
Correct |
8 ms |
4912 KB |
Output is correct |
20 |
Correct |
12 ms |
4992 KB |
Output is correct |
21 |
Correct |
12 ms |
5200 KB |
Output is correct |
22 |
Correct |
7 ms |
5060 KB |
Output is correct |
23 |
Correct |
5 ms |
5008 KB |
Output is correct |
24 |
Correct |
6 ms |
4992 KB |
Output is correct |
25 |
Correct |
33 ms |
5112 KB |
Output is correct |
26 |
Correct |
21 ms |
5112 KB |
Output is correct |
27 |
Correct |
6 ms |
4992 KB |
Output is correct |
28 |
Correct |
44 ms |
5388 KB |
Output is correct |
29 |
Correct |
35 ms |
5176 KB |
Output is correct |
30 |
Correct |
22 ms |
5452 KB |
Output is correct |
31 |
Correct |
6 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5148 KB |
Output is correct |
33 |
Correct |
6 ms |
4992 KB |
Output is correct |
34 |
Correct |
17 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5136 KB |
Output is correct |
36 |
Correct |
12 ms |
5156 KB |
Output is correct |
37 |
Correct |
6 ms |
5124 KB |
Output is correct |
38 |
Correct |
7 ms |
4992 KB |
Output is correct |
39 |
Correct |
20 ms |
5120 KB |
Output is correct |
40 |
Correct |
20 ms |
5376 KB |
Output is correct |
41 |
Correct |
21 ms |
5240 KB |
Output is correct |
42 |
Correct |
16 ms |
5300 KB |
Output is correct |
43 |
Correct |
14 ms |
5276 KB |
Output is correct |
44 |
Correct |
13 ms |
5124 KB |
Output is correct |
45 |
Correct |
10 ms |
5200 KB |
Output is correct |
46 |
Correct |
6 ms |
5112 KB |
Output is correct |
47 |
Correct |
27 ms |
5112 KB |
Output is correct |
48 |
Correct |
24 ms |
5132 KB |
Output is correct |
49 |
Correct |
7 ms |
5120 KB |
Output is correct |
50 |
Correct |
49 ms |
5240 KB |
Output is correct |
51 |
Correct |
16 ms |
5112 KB |
Output is correct |
52 |
Correct |
6 ms |
5128 KB |
Output is correct |
53 |
Correct |
7 ms |
4992 KB |
Output is correct |
54 |
Correct |
17 ms |
5068 KB |
Output is correct |
55 |
Correct |
6 ms |
4992 KB |
Output is correct |
56 |
Correct |
22 ms |
5452 KB |
Output is correct |
57 |
Correct |
39 ms |
5240 KB |
Output is correct |
58 |
Correct |
20 ms |
5112 KB |
Output is correct |
59 |
Correct |
23 ms |
5160 KB |
Output is correct |
60 |
Correct |
23 ms |
5240 KB |
Output is correct |
61 |
Correct |
6 ms |
5124 KB |
Output is correct |
62 |
Correct |
6 ms |
5012 KB |
Output is correct |
63 |
Correct |
6 ms |
5132 KB |
Output is correct |
64 |
Correct |
6 ms |
5132 KB |
Output is correct |
65 |
Incorrect |
81 ms |
5252 KB |
Incorrect |
66 |
Halted |
0 ms |
0 KB |
- |