#include "prize.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
struct pii{int a, b;};
typedef vector<int> vi;
vi getVal(int i, map<int, vi>& cache) {
if(cache.count(i)) return cache[i];
return cache[i] = ask(i);
}
void getBetter(int l, int r, int loid, int lOff, int rOff, map<int, vi>& cache) {
assert(l <= r);
int mid = (l + r) / 2;
REP(ci, mid, r+1) {
vi cv = getVal(ci, cache);
if(cv[0] + cv[1] == loid) {
if(cv[0] + lOff > 0) getBetter(l, ci - 1, loid, lOff, -cv[1], cache);
if(cv[1] + rOff > 0) getBetter(ci+1, r, loid, -cv[0], rOff, cache);
return;
}
}
for(int ci = mid - 1; ci >= l; --ci) {
vi cv = getVal(ci, cache);
if(cv[0] + cv[1] == loid) {
if(cv[0] + lOff > 0) getBetter(l, ci - 1, loid, lOff, -cv[1], cache);
if(cv[1] + rOff > 0) getBetter(ci+1, r, loid, -cv[0], rOff, cache);
return;
}
}
}
const int MV = 450;
int find_best(int n){
map<int, vi> ca;
forR(i, min(n, MV)) getVal(i, ca);
int loVal = ca[0][0] + ca[0][1];
forR(i, min(n, MV)) loVal = max(loVal, ca[i][0] + ca[i][1]);
getBetter(0, n-1, loVal, 0, 0, ca);
int bi = -1;
for(auto [ci, cv] : ca) if(cv[0] + cv[1] == 0) {
bi = ci;
}
assert(bi != -1);
return bi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
424 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
464 KB |
Output is correct |
9 |
Correct |
3 ms |
428 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
428 KB |
Output is correct |
14 |
Correct |
7 ms |
644 KB |
Output is correct |
15 |
Correct |
21 ms |
1112 KB |
Output is correct |
16 |
Partially correct |
21 ms |
956 KB |
Partially correct - number of queries: 5206 |
17 |
Partially correct |
30 ms |
800 KB |
Partially correct - number of queries: 5209 |
18 |
Partially correct |
17 ms |
1112 KB |
Partially correct - number of queries: 5206 |
19 |
Correct |
14 ms |
892 KB |
Output is correct |
20 |
Correct |
10 ms |
876 KB |
Output is correct |
21 |
Partially correct |
17 ms |
1188 KB |
Partially correct - number of queries: 5174 |
22 |
Correct |
15 ms |
856 KB |
Output is correct |
23 |
Correct |
3 ms |
344 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
28 ms |
764 KB |
Output is correct |
26 |
Correct |
20 ms |
1112 KB |
Output is correct |
27 |
Correct |
3 ms |
600 KB |
Output is correct |
28 |
Correct |
19 ms |
848 KB |
Output is correct |
29 |
Correct |
24 ms |
848 KB |
Output is correct |
30 |
Partially correct |
30 ms |
764 KB |
Partially correct - number of queries: 5175 |
31 |
Partially correct |
21 ms |
764 KB |
Partially correct - number of queries: 5173 |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Partially correct |
22 ms |
1492 KB |
Partially correct - number of queries: 5211 |
35 |
Correct |
3 ms |
344 KB |
Output is correct |
36 |
Partially correct |
17 ms |
848 KB |
Partially correct - number of queries: 5174 |
37 |
Correct |
5 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Partially correct |
22 ms |
1348 KB |
Partially correct - number of queries: 5174 |
40 |
Correct |
13 ms |
916 KB |
Output is correct |
41 |
Partially correct |
24 ms |
864 KB |
Partially correct - number of queries: 5210 |
42 |
Partially correct |
16 ms |
916 KB |
Partially correct - number of queries: 5210 |
43 |
Partially correct |
25 ms |
864 KB |
Partially correct - number of queries: 5076 |
44 |
Partially correct |
24 ms |
948 KB |
Partially correct - number of queries: 5209 |
45 |
Correct |
19 ms |
856 KB |
Output is correct |
46 |
Partially correct |
32 ms |
1104 KB |
Partially correct - number of queries: 5208 |
47 |
Correct |
24 ms |
760 KB |
Output is correct |
48 |
Partially correct |
18 ms |
1260 KB |
Partially correct - number of queries: 5208 |
49 |
Partially correct |
30 ms |
1100 KB |
Partially correct - number of queries: 5206 |
50 |
Partially correct |
19 ms |
1140 KB |
Partially correct - number of queries: 5211 |
51 |
Partially correct |
16 ms |
848 KB |
Partially correct - number of queries: 5205 |
52 |
Partially correct |
22 ms |
804 KB |
Partially correct - number of queries: 5209 |
53 |
Correct |
3 ms |
344 KB |
Output is correct |
54 |
Partially correct |
21 ms |
1072 KB |
Partially correct - number of queries: 5178 |
55 |
Partially correct |
21 ms |
856 KB |
Partially correct - number of queries: 5207 |
56 |
Partially correct |
21 ms |
1420 KB |
Partially correct - number of queries: 5210 |
57 |
Partially correct |
18 ms |
956 KB |
Partially correct - number of queries: 5173 |
58 |
Partially correct |
21 ms |
948 KB |
Partially correct - number of queries: 5208 |
59 |
Partially correct |
16 ms |
1088 KB |
Partially correct - number of queries: 5214 |
60 |
Partially correct |
14 ms |
848 KB |
Partially correct - number of queries: 5172 |
61 |
Correct |
3 ms |
344 KB |
Output is correct |
62 |
Correct |
3 ms |
344 KB |
Output is correct |
63 |
Correct |
3 ms |
344 KB |
Output is correct |
64 |
Correct |
2 ms |
344 KB |
Output is correct |
65 |
Correct |
2 ms |
428 KB |
Output is correct |
66 |
Correct |
4 ms |
340 KB |
Output is correct |
67 |
Correct |
3 ms |
344 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
4 ms |
344 KB |
Output is correct |
70 |
Correct |
3 ms |
344 KB |
Output is correct |
71 |
Partially correct |
20 ms |
900 KB |
Partially correct - number of queries: 5208 |
72 |
Correct |
6 ms |
856 KB |
Output is correct |
73 |
Partially correct |
21 ms |
988 KB |
Partially correct - number of queries: 5145 |
74 |
Partially correct |
19 ms |
788 KB |
Partially correct - number of queries: 5172 |
75 |
Correct |
4 ms |
344 KB |
Output is correct |
76 |
Correct |
19 ms |
848 KB |
Output is correct |
77 |
Partially correct |
20 ms |
796 KB |
Partially correct - number of queries: 5333 |
78 |
Correct |
5 ms |
472 KB |
Output is correct |
79 |
Correct |
11 ms |
848 KB |
Output is correct |
80 |
Partially correct |
33 ms |
848 KB |
Partially correct - number of queries: 5324 |
81 |
Partially correct |
20 ms |
988 KB |
Partially correct - number of queries: 5324 |
82 |
Partially correct |
20 ms |
1104 KB |
Partially correct - number of queries: 5266 |
83 |
Correct |
3 ms |
344 KB |
Output is correct |
84 |
Correct |
21 ms |
848 KB |
Output is correct |
85 |
Partially correct |
22 ms |
1112 KB |
Partially correct - number of queries: 5288 |
86 |
Incorrect |
43 ms |
1528 KB |
Incorrect |
87 |
Halted |
0 ms |
0 KB |
- |