#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
vector<vector<int>> memo(MAXN, vector<int>(2, -1));
vector<int> _ask(int i) {
if (memo[i][0] != -1) return memo[i];
return memo[i] = ask(i);
}
int find_best(int n) {
int mx = 0;
int sqrtn = sqrt(n);
int k = 0;
for(int i = 0; i < sqrtn; i++) {
vector<int> res = _ask(i);
if(res[0] + res[1] == 0) return i;
mx = max(mx, res[0] + res[1]);
}
for (int i = sqrtn; i < n; ++i) {
auto res = _ask(i);
if (res[0] + res[1] < mx) {
if (res[0] + res[1] == 0) return i;
continue;
}
int l = i, r = n-1;
int tmp = i;
while(l<r) {
int mid = (l+r)/2;
auto rmid = _ask(mid);
if (rmid[0]+rmid[1] < mx || rmid[1] < res[1]) {
if (rmid[0]+rmid[1] == 0) return mid;
r = mid;
} else {
l = mid+1;
tmp = mid;
}
}
i = tmp;
}
return 0;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:16:6: warning: unused variable 'k' [-Wunused-variable]
16 | int k = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
11216 KB |
Output is correct |
2 |
Correct |
10 ms |
11344 KB |
Output is correct |
3 |
Correct |
13 ms |
11216 KB |
Output is correct |
4 |
Correct |
12 ms |
11216 KB |
Output is correct |
5 |
Correct |
16 ms |
11216 KB |
Output is correct |
6 |
Correct |
9 ms |
11264 KB |
Output is correct |
7 |
Correct |
12 ms |
11264 KB |
Output is correct |
8 |
Correct |
12 ms |
11268 KB |
Output is correct |
9 |
Correct |
10 ms |
11216 KB |
Output is correct |
10 |
Correct |
12 ms |
11216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11260 KB |
Output is correct |
2 |
Correct |
12 ms |
11204 KB |
Output is correct |
3 |
Correct |
11 ms |
11216 KB |
Output is correct |
4 |
Correct |
10 ms |
11260 KB |
Output is correct |
5 |
Correct |
11 ms |
11268 KB |
Output is correct |
6 |
Correct |
9 ms |
11216 KB |
Output is correct |
7 |
Correct |
12 ms |
11216 KB |
Output is correct |
8 |
Correct |
11 ms |
11268 KB |
Output is correct |
9 |
Correct |
11 ms |
11268 KB |
Output is correct |
10 |
Correct |
13 ms |
11252 KB |
Output is correct |
11 |
Correct |
15 ms |
11156 KB |
Output is correct |
12 |
Correct |
11 ms |
11268 KB |
Output is correct |
13 |
Correct |
13 ms |
11260 KB |
Output is correct |
14 |
Correct |
12 ms |
11216 KB |
Output is correct |
15 |
Correct |
22 ms |
11216 KB |
Output is correct |
16 |
Partially correct |
37 ms |
11268 KB |
Partially correct - number of queries: 7088 |
17 |
Correct |
11 ms |
11260 KB |
Output is correct |
18 |
Partially correct |
56 ms |
11260 KB |
Partially correct - number of queries: 8230 |
19 |
Correct |
12 ms |
11264 KB |
Output is correct |
20 |
Correct |
23 ms |
11216 KB |
Output is correct |
21 |
Correct |
30 ms |
11256 KB |
Output is correct |
22 |
Correct |
19 ms |
11216 KB |
Output is correct |
23 |
Correct |
12 ms |
11216 KB |
Output is correct |
24 |
Correct |
13 ms |
11268 KB |
Output is correct |
25 |
Correct |
37 ms |
11240 KB |
Output is correct |
26 |
Correct |
33 ms |
11240 KB |
Output is correct |
27 |
Correct |
11 ms |
11204 KB |
Output is correct |
28 |
Partially correct |
71 ms |
11216 KB |
Partially correct - number of queries: 7790 |
29 |
Partially correct |
60 ms |
11248 KB |
Partially correct - number of queries: 6009 |
30 |
Partially correct |
37 ms |
11264 KB |
Partially correct - number of queries: 8186 |
31 |
Correct |
16 ms |
11220 KB |
Output is correct |
32 |
Correct |
14 ms |
11216 KB |
Output is correct |
33 |
Correct |
9 ms |
11216 KB |
Output is correct |
34 |
Correct |
34 ms |
11216 KB |
Output is correct |
35 |
Correct |
14 ms |
11364 KB |
Output is correct |
36 |
Correct |
34 ms |
11260 KB |
Output is correct |
37 |
Correct |
14 ms |
11216 KB |
Output is correct |
38 |
Correct |
10 ms |
11264 KB |
Output is correct |
39 |
Correct |
45 ms |
11268 KB |
Output is correct |
40 |
Partially correct |
60 ms |
11272 KB |
Partially correct - number of queries: 7082 |
41 |
Partially correct |
28 ms |
11284 KB |
Partially correct - number of queries: 5122 |
42 |
Partially correct |
36 ms |
11216 KB |
Partially correct - number of queries: 5122 |
43 |
Correct |
39 ms |
11260 KB |
Output is correct |
44 |
Correct |
42 ms |
11268 KB |
Output is correct |
45 |
Correct |
35 ms |
11268 KB |
Output is correct |
46 |
Correct |
17 ms |
11216 KB |
Output is correct |
47 |
Correct |
23 ms |
11264 KB |
Output is correct |
48 |
Partially correct |
30 ms |
11252 KB |
Partially correct - number of queries: 6221 |
49 |
Correct |
12 ms |
11264 KB |
Output is correct |
50 |
Partially correct |
53 ms |
11216 KB |
Partially correct - number of queries: 8218 |
51 |
Correct |
23 ms |
11344 KB |
Output is correct |
52 |
Correct |
17 ms |
11216 KB |
Output is correct |
53 |
Correct |
13 ms |
11264 KB |
Output is correct |
54 |
Correct |
22 ms |
11264 KB |
Output is correct |
55 |
Correct |
12 ms |
11264 KB |
Output is correct |
56 |
Partially correct |
37 ms |
11268 KB |
Partially correct - number of queries: 8232 |
57 |
Partially correct |
67 ms |
11216 KB |
Partially correct - number of queries: 6108 |
58 |
Partially correct |
62 ms |
11264 KB |
Partially correct - number of queries: 6200 |
59 |
Partially correct |
57 ms |
11140 KB |
Partially correct - number of queries: 5123 |
60 |
Correct |
32 ms |
11256 KB |
Output is correct |
61 |
Correct |
12 ms |
11264 KB |
Output is correct |
62 |
Correct |
12 ms |
11216 KB |
Output is correct |
63 |
Correct |
12 ms |
11264 KB |
Output is correct |
64 |
Correct |
14 ms |
11216 KB |
Output is correct |
65 |
Correct |
13 ms |
11160 KB |
Output is correct |
66 |
Correct |
16 ms |
11264 KB |
Output is correct |
67 |
Correct |
11 ms |
11336 KB |
Output is correct |
68 |
Correct |
11 ms |
11268 KB |
Output is correct |
69 |
Correct |
15 ms |
11264 KB |
Output is correct |
70 |
Correct |
13 ms |
11216 KB |
Output is correct |
71 |
Partially correct |
53 ms |
11208 KB |
Partially correct - number of queries: 8253 |
72 |
Correct |
16 ms |
11216 KB |
Output is correct |
73 |
Partially correct |
61 ms |
11216 KB |
Partially correct - number of queries: 8126 |
74 |
Partially correct |
52 ms |
11256 KB |
Partially correct - number of queries: 8180 |
75 |
Correct |
13 ms |
11216 KB |
Output is correct |
76 |
Partially correct |
51 ms |
11212 KB |
Partially correct - number of queries: 7067 |
77 |
Partially correct |
77 ms |
11216 KB |
Partially correct - number of queries: 8313 |
78 |
Correct |
17 ms |
11216 KB |
Output is correct |
79 |
Correct |
41 ms |
11216 KB |
Output is correct |
80 |
Partially correct |
75 ms |
11216 KB |
Partially correct - number of queries: 8310 |
81 |
Partially correct |
47 ms |
11216 KB |
Partially correct - number of queries: 8281 |
82 |
Partially correct |
63 ms |
11216 KB |
Partially correct - number of queries: 8216 |
83 |
Correct |
12 ms |
11216 KB |
Output is correct |
84 |
Partially correct |
62 ms |
11228 KB |
Partially correct - number of queries: 6819 |
85 |
Partially correct |
63 ms |
11264 KB |
Partially correct - number of queries: 8260 |
86 |
Correct |
12 ms |
11216 KB |
Output is correct |
87 |
Correct |
11 ms |
11216 KB |
Output is correct |
88 |
Correct |
12 ms |
11216 KB |
Output is correct |
89 |
Correct |
11 ms |
11172 KB |
Output is correct |
90 |
Correct |
11 ms |
11216 KB |
Output is correct |
91 |
Correct |
13 ms |
11216 KB |
Output is correct |
92 |
Correct |
11 ms |
11216 KB |
Output is correct |
93 |
Correct |
16 ms |
11216 KB |
Output is correct |
94 |
Correct |
16 ms |
11148 KB |
Output is correct |
95 |
Correct |
18 ms |
11216 KB |
Output is correct |
96 |
Correct |
14 ms |
11216 KB |
Output is correct |
97 |
Correct |
12 ms |
11216 KB |
Output is correct |