#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 = 500;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
432 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 |
428 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
3 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 |
3 ms |
428 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Partially correct |
19 ms |
768 KB |
Partially correct - number of queries: 5032 |
16 |
Partially correct |
17 ms |
1104 KB |
Partially correct - number of queries: 5255 |
17 |
Partially correct |
25 ms |
960 KB |
Partially correct - number of queries: 5258 |
18 |
Partially correct |
20 ms |
916 KB |
Partially correct - number of queries: 5255 |
19 |
Correct |
19 ms |
804 KB |
Output is correct |
20 |
Correct |
18 ms |
784 KB |
Output is correct |
21 |
Partially correct |
30 ms |
952 KB |
Partially correct - number of queries: 5223 |
22 |
Correct |
17 ms |
848 KB |
Output is correct |
23 |
Correct |
3 ms |
464 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
25 ms |
772 KB |
Output is correct |
26 |
Correct |
18 ms |
848 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
29 ms |
1388 KB |
Output is correct |
29 |
Correct |
16 ms |
856 KB |
Output is correct |
30 |
Partially correct |
21 ms |
848 KB |
Partially correct - number of queries: 5224 |
31 |
Partially correct |
28 ms |
752 KB |
Partially correct - number of queries: 5222 |
32 |
Correct |
4 ms |
452 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Partially correct |
22 ms |
796 KB |
Partially correct - number of queries: 5260 |
35 |
Correct |
4 ms |
464 KB |
Output is correct |
36 |
Partially correct |
21 ms |
1040 KB |
Partially correct - number of queries: 5223 |
37 |
Correct |
4 ms |
344 KB |
Output is correct |
38 |
Correct |
2 ms |
344 KB |
Output is correct |
39 |
Partially correct |
26 ms |
976 KB |
Partially correct - number of queries: 5223 |
40 |
Correct |
26 ms |
856 KB |
Output is correct |
41 |
Partially correct |
32 ms |
848 KB |
Partially correct - number of queries: 5259 |
42 |
Partially correct |
24 ms |
968 KB |
Partially correct - number of queries: 5259 |
43 |
Partially correct |
17 ms |
960 KB |
Partially correct - number of queries: 5125 |
44 |
Partially correct |
21 ms |
856 KB |
Partially correct - number of queries: 5258 |
45 |
Correct |
33 ms |
696 KB |
Output is correct |
46 |
Partially correct |
27 ms |
1220 KB |
Partially correct - number of queries: 5257 |
47 |
Correct |
24 ms |
992 KB |
Output is correct |
48 |
Partially correct |
16 ms |
848 KB |
Partially correct - number of queries: 5257 |
49 |
Partially correct |
20 ms |
856 KB |
Partially correct - number of queries: 5255 |
50 |
Partially correct |
17 ms |
856 KB |
Partially correct - number of queries: 5260 |
51 |
Partially correct |
26 ms |
1268 KB |
Partially correct - number of queries: 5254 |
52 |
Partially correct |
16 ms |
936 KB |
Partially correct - number of queries: 5258 |
53 |
Correct |
3 ms |
340 KB |
Output is correct |
54 |
Partially correct |
40 ms |
916 KB |
Partially correct - number of queries: 5227 |
55 |
Partially correct |
20 ms |
944 KB |
Partially correct - number of queries: 5256 |
56 |
Partially correct |
27 ms |
888 KB |
Partially correct - number of queries: 5259 |
57 |
Partially correct |
22 ms |
856 KB |
Partially correct - number of queries: 5222 |
58 |
Partially correct |
28 ms |
944 KB |
Partially correct - number of queries: 5257 |
59 |
Partially correct |
36 ms |
936 KB |
Partially correct - number of queries: 5263 |
60 |
Partially correct |
27 ms |
1648 KB |
Partially correct - number of queries: 5221 |
61 |
Correct |
3 ms |
344 KB |
Output is correct |
62 |
Correct |
3 ms |
344 KB |
Output is correct |
63 |
Correct |
3 ms |
496 KB |
Output is correct |
64 |
Correct |
3 ms |
344 KB |
Output is correct |
65 |
Correct |
3 ms |
344 KB |
Output is correct |
66 |
Correct |
6 ms |
452 KB |
Output is correct |
67 |
Correct |
3 ms |
344 KB |
Output is correct |
68 |
Correct |
2 ms |
344 KB |
Output is correct |
69 |
Correct |
4 ms |
600 KB |
Output is correct |
70 |
Correct |
4 ms |
428 KB |
Output is correct |
71 |
Partially correct |
19 ms |
1148 KB |
Partially correct - number of queries: 5258 |
72 |
Correct |
3 ms |
344 KB |
Output is correct |
73 |
Partially correct |
25 ms |
852 KB |
Partially correct - number of queries: 5195 |
74 |
Partially correct |
22 ms |
904 KB |
Partially correct - number of queries: 5222 |
75 |
Correct |
3 ms |
340 KB |
Output is correct |
76 |
Correct |
23 ms |
788 KB |
Output is correct |
77 |
Partially correct |
22 ms |
1064 KB |
Partially correct - number of queries: 5396 |
78 |
Correct |
3 ms |
600 KB |
Output is correct |
79 |
Correct |
8 ms |
600 KB |
Output is correct |
80 |
Partially correct |
25 ms |
1072 KB |
Partially correct - number of queries: 5380 |
81 |
Partially correct |
14 ms |
856 KB |
Partially correct - number of queries: 5366 |
82 |
Partially correct |
16 ms |
848 KB |
Partially correct - number of queries: 5318 |
83 |
Correct |
2 ms |
344 KB |
Output is correct |
84 |
Correct |
25 ms |
848 KB |
Output is correct |
85 |
Partially correct |
22 ms |
848 KB |
Partially correct - number of queries: 5334 |
86 |
Correct |
2 ms |
344 KB |
Output is correct |
87 |
Correct |
2 ms |
344 KB |
Output is correct |
88 |
Correct |
2 ms |
344 KB |
Output is correct |
89 |
Correct |
3 ms |
344 KB |
Output is correct |
90 |
Correct |
3 ms |
344 KB |
Output is correct |
91 |
Correct |
3 ms |
344 KB |
Output is correct |
92 |
Correct |
4 ms |
344 KB |
Output is correct |
93 |
Correct |
4 ms |
344 KB |
Output is correct |
94 |
Correct |
5 ms |
344 KB |
Output is correct |
95 |
Correct |
4 ms |
344 KB |
Output is correct |
96 |
Correct |
4 ms |
340 KB |
Output is correct |
97 |
Correct |
4 ms |
344 KB |
Output is correct |