#include "bits/stdc++.h"
#include "prize.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
const int N = 2e5 + 5;
int mx = -1, n;
vector<bool> mark(N, 0);
map<int,vector<int>> dp;
vector<int> Ask(int i){
if(dp.count(i)) return dp[i];
return dp[i] = ask(i);
}
void Learn(int l, int r){
if(l > r) return;
if(l == r){
mark[l] = 1;
return;
}
int mid = (l+r)/2 , p = -1;
for(int i=0;i<=(r-l+1)/2;i++){
if(mid+i<=r){
vector<int> x = Ask(mid+i);
if(x[0]+x[1]==mx){
p=mid+i;
break;
}
mark[mid+i]=1;
}
if(mid-i>=l){
vector<int> x = Ask(mid-i);
if(x[0]+x[1]==mx){
p=mid-i;
break;
}
mark[mid-i]=1;
}
}
if(p == -1) return;
if(l < p && Ask(p)[0] - (l > 0 ? Ask(l-1)[0] : 0) ) Learn(l, p - 1);
if(p < r && Ask(p)[1] - (r + 1 < n ? Ask(r + 1)[1] : 0) ) Learn(p + 1, r);
}
int find_best(int _n){
n = _n;
for(int i = 0; i < min(n, 475); i++){
vector<int> x = Ask(i);
if(x[0] + x[1] == 0) return i;
mx = max(mx, x[0] + x[1]);
if(mx > 30) break;
}
Learn(0, n - 1);
for(int i = 0 ; i < n ; i++){
if(mark[i]){
vector<int> x = Ask(i);
if(x[0] + x[1] == 0) return i;
}
}
return -23;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
336 KB |
Output is correct |
2 |
Correct |
9 ms |
336 KB |
Output is correct |
3 |
Correct |
8 ms |
508 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
9 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
9 ms |
1364 KB |
Output is correct |
8 |
Correct |
9 ms |
592 KB |
Output is correct |
9 |
Correct |
8 ms |
592 KB |
Output is correct |
10 |
Correct |
10 ms |
496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
336 KB |
Output is correct |
3 |
Correct |
9 ms |
336 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
592 KB |
Output is correct |
8 |
Correct |
9 ms |
504 KB |
Output is correct |
9 |
Correct |
9 ms |
336 KB |
Output is correct |
10 |
Correct |
10 ms |
592 KB |
Output is correct |
11 |
Correct |
7 ms |
336 KB |
Output is correct |
12 |
Correct |
9 ms |
592 KB |
Output is correct |
13 |
Correct |
10 ms |
336 KB |
Output is correct |
14 |
Correct |
17 ms |
544 KB |
Output is correct |
15 |
Correct |
72 ms |
784 KB |
Output is correct |
16 |
Correct |
82 ms |
1496 KB |
Output is correct |
17 |
Correct |
95 ms |
1148 KB |
Output is correct |
18 |
Correct |
89 ms |
1092 KB |
Output is correct |
19 |
Correct |
83 ms |
960 KB |
Output is correct |
20 |
Correct |
48 ms |
1212 KB |
Output is correct |
21 |
Correct |
88 ms |
1072 KB |
Output is correct |
22 |
Correct |
66 ms |
856 KB |
Output is correct |
23 |
Correct |
10 ms |
336 KB |
Output is correct |
24 |
Correct |
8 ms |
500 KB |
Output is correct |
25 |
Correct |
66 ms |
1268 KB |
Output is correct |
26 |
Correct |
70 ms |
1012 KB |
Output is correct |
27 |
Correct |
11 ms |
592 KB |
Output is correct |
28 |
Correct |
69 ms |
1408 KB |
Output is correct |
29 |
Correct |
65 ms |
852 KB |
Output is correct |
30 |
Correct |
89 ms |
1052 KB |
Output is correct |
31 |
Correct |
74 ms |
1084 KB |
Output is correct |
32 |
Correct |
8 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
89 ms |
1268 KB |
Output is correct |
35 |
Correct |
13 ms |
336 KB |
Output is correct |
36 |
Correct |
81 ms |
868 KB |
Output is correct |
37 |
Correct |
8 ms |
728 KB |
Output is correct |
38 |
Correct |
10 ms |
336 KB |
Output is correct |
39 |
Correct |
91 ms |
1072 KB |
Output is correct |
40 |
Correct |
79 ms |
1196 KB |
Output is correct |
41 |
Correct |
79 ms |
1264 KB |
Output is correct |
42 |
Correct |
91 ms |
828 KB |
Output is correct |
43 |
Correct |
93 ms |
1592 KB |
Output is correct |
44 |
Correct |
101 ms |
968 KB |
Output is correct |
45 |
Correct |
75 ms |
992 KB |
Output is correct |
46 |
Correct |
89 ms |
1356 KB |
Output is correct |
47 |
Correct |
87 ms |
984 KB |
Output is correct |
48 |
Correct |
105 ms |
1072 KB |
Output is correct |
49 |
Correct |
85 ms |
1124 KB |
Output is correct |
50 |
Correct |
85 ms |
900 KB |
Output is correct |
51 |
Correct |
86 ms |
916 KB |
Output is correct |
52 |
Correct |
90 ms |
1620 KB |
Output is correct |
53 |
Correct |
10 ms |
336 KB |
Output is correct |
54 |
Correct |
85 ms |
1132 KB |
Output is correct |
55 |
Correct |
83 ms |
804 KB |
Output is correct |
56 |
Correct |
71 ms |
1172 KB |
Output is correct |
57 |
Correct |
80 ms |
1052 KB |
Output is correct |
58 |
Correct |
82 ms |
872 KB |
Output is correct |
59 |
Correct |
82 ms |
1200 KB |
Output is correct |
60 |
Correct |
87 ms |
1568 KB |
Output is correct |
61 |
Correct |
10 ms |
528 KB |
Output is correct |
62 |
Correct |
10 ms |
336 KB |
Output is correct |
63 |
Correct |
9 ms |
1292 KB |
Output is correct |
64 |
Correct |
10 ms |
504 KB |
Output is correct |
65 |
Correct |
2 ms |
336 KB |
Output is correct |
66 |
Correct |
9 ms |
336 KB |
Output is correct |
67 |
Correct |
8 ms |
592 KB |
Output is correct |
68 |
Correct |
7 ms |
336 KB |
Output is correct |
69 |
Correct |
7 ms |
504 KB |
Output is correct |
70 |
Correct |
7 ms |
336 KB |
Output is correct |
71 |
Correct |
98 ms |
1076 KB |
Output is correct |
72 |
Correct |
7 ms |
336 KB |
Output is correct |
73 |
Correct |
77 ms |
892 KB |
Output is correct |
74 |
Correct |
86 ms |
1704 KB |
Output is correct |
75 |
Correct |
10 ms |
592 KB |
Output is correct |
76 |
Correct |
69 ms |
956 KB |
Output is correct |
77 |
Correct |
101 ms |
1096 KB |
Output is correct |
78 |
Correct |
8 ms |
336 KB |
Output is correct |
79 |
Correct |
43 ms |
620 KB |
Output is correct |
80 |
Correct |
88 ms |
1352 KB |
Output is correct |
81 |
Correct |
91 ms |
1772 KB |
Output is correct |
82 |
Correct |
84 ms |
988 KB |
Output is correct |
83 |
Correct |
12 ms |
336 KB |
Output is correct |
84 |
Correct |
84 ms |
1072 KB |
Output is correct |
85 |
Correct |
96 ms |
836 KB |
Output is correct |
86 |
Correct |
10 ms |
592 KB |
Output is correct |
87 |
Correct |
2 ms |
336 KB |
Output is correct |
88 |
Correct |
9 ms |
336 KB |
Output is correct |
89 |
Correct |
6 ms |
336 KB |
Output is correct |
90 |
Correct |
10 ms |
592 KB |
Output is correct |
91 |
Correct |
6 ms |
336 KB |
Output is correct |
92 |
Correct |
6 ms |
336 KB |
Output is correct |
93 |
Correct |
14 ms |
336 KB |
Output is correct |
94 |
Correct |
16 ms |
592 KB |
Output is correct |
95 |
Correct |
16 ms |
740 KB |
Output is correct |
96 |
Correct |
11 ms |
336 KB |
Output is correct |
97 |
Correct |
7 ms |
336 KB |
Output is correct |