#include "prize.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
#include <random>
using namespace std;
#define rep(i,n)for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
typedef pair<int, int> P;
int mp = 0;
P cache[200000];
int Q=0;
P query(int x) {
if (cache[x] != P(-1, -1)) return cache[x];
Q++;
assert(Q<=10000);
vector<int> ret = ask(x);
mp = max(mp, ret[0]+ret[1]);
return cache[x] = {ret[0], ret[1]};
}
int solve(int l, int r, int num, int left) {
assert(num >= 0 && left >= 0);
if (num == 0) return -1;
//cout<<"solve("<<l<<","<<r<<", num="<<num<<")\n";
int mm = (l+r)/2;
vector<P> list;
for (int mid=mm; mid>=l; mid--) list.pb(P(mm-mid, mid));
for (int mid=mm+1; mid<=r; mid++) list.pb(P(mid-mm, mid));
sort(all(list));
for (P p : list) {
int mid = p._2;
P ret = query(mid);
if (ret._1+ret._2 == 0) return mid;
if (ret._1+ret._2 != mp) continue;
if (mid > l) {
int o = solve(l, mid-1, ret._1-left, left);
if (o != -1) return o;
}
if (mid < r) {
int o = solve(mid+1, r, num-(ret._1-left), ret._1);
if (o != -1) return o;
}
return -1;
}
return -1;
}
int find_best(int N) {
rep(i, N) cache[i] = P(-1, -1);
if (N <= 5000) {
rep(i, N) {
P ret = query(i);
if (ret._1+ret._2 == 0) return i;
}
abort();
}
//472
query((0+N-1)/2);
rep(i, 471) query(i);
int r = solve(0, N-1, mp, 0);
assert(r != -1);
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
5220 KB |
Output is correct |
2 |
Correct |
57 ms |
5220 KB |
Output is correct |
3 |
Correct |
57 ms |
5348 KB |
Output is correct |
4 |
Correct |
55 ms |
5348 KB |
Output is correct |
5 |
Correct |
59 ms |
5392 KB |
Output is correct |
6 |
Correct |
57 ms |
5392 KB |
Output is correct |
7 |
Correct |
58 ms |
5392 KB |
Output is correct |
8 |
Correct |
61 ms |
5468 KB |
Output is correct |
9 |
Correct |
41 ms |
5468 KB |
Output is correct |
10 |
Correct |
59 ms |
5468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
5468 KB |
Output is correct |
2 |
Correct |
74 ms |
5468 KB |
Output is correct |
3 |
Correct |
77 ms |
5496 KB |
Output is correct |
4 |
Correct |
66 ms |
5496 KB |
Output is correct |
5 |
Correct |
62 ms |
5496 KB |
Output is correct |
6 |
Correct |
73 ms |
5544 KB |
Output is correct |
7 |
Correct |
60 ms |
5544 KB |
Output is correct |
8 |
Correct |
60 ms |
5544 KB |
Output is correct |
9 |
Correct |
45 ms |
5544 KB |
Output is correct |
10 |
Correct |
60 ms |
5544 KB |
Output is correct |
11 |
Correct |
104 ms |
5544 KB |
Output is correct |
12 |
Correct |
61 ms |
5544 KB |
Output is correct |
13 |
Correct |
183 ms |
5544 KB |
Output is correct |
14 |
Correct |
14 ms |
5544 KB |
Output is correct |
15 |
Correct |
91 ms |
5544 KB |
Output is correct |
16 |
Correct |
259 ms |
5544 KB |
Output is correct |
17 |
Correct |
62 ms |
5544 KB |
Output is correct |
18 |
Partially correct |
300 ms |
5604 KB |
Partially correct - number of queries: 5225 |
19 |
Correct |
70 ms |
5604 KB |
Output is correct |
20 |
Correct |
79 ms |
5604 KB |
Output is correct |
21 |
Correct |
142 ms |
5604 KB |
Output is correct |
22 |
Correct |
76 ms |
5604 KB |
Output is correct |
23 |
Correct |
61 ms |
5604 KB |
Output is correct |
24 |
Correct |
75 ms |
5604 KB |
Output is correct |
25 |
Correct |
201 ms |
5604 KB |
Output is correct |
26 |
Correct |
224 ms |
5604 KB |
Output is correct |
27 |
Correct |
81 ms |
5604 KB |
Output is correct |
28 |
Correct |
330 ms |
5604 KB |
Output is correct |
29 |
Correct |
255 ms |
5604 KB |
Output is correct |
30 |
Partially correct |
336 ms |
5604 KB |
Partially correct - number of queries: 5193 |
31 |
Correct |
63 ms |
5604 KB |
Output is correct |
32 |
Correct |
149 ms |
5604 KB |
Output is correct |
33 |
Correct |
2 ms |
5604 KB |
Output is correct |
34 |
Correct |
130 ms |
5604 KB |
Output is correct |
35 |
Correct |
119 ms |
5604 KB |
Output is correct |
36 |
Correct |
100 ms |
5604 KB |
Output is correct |
37 |
Correct |
84 ms |
5604 KB |
Output is correct |
38 |
Correct |
70 ms |
5604 KB |
Output is correct |
39 |
Correct |
148 ms |
5604 KB |
Output is correct |
40 |
Correct |
273 ms |
5604 KB |
Output is correct |
41 |
Correct |
203 ms |
5604 KB |
Output is correct |
42 |
Correct |
191 ms |
5604 KB |
Output is correct |
43 |
Correct |
181 ms |
5604 KB |
Output is correct |
44 |
Correct |
148 ms |
5604 KB |
Output is correct |
45 |
Correct |
119 ms |
5604 KB |
Output is correct |
46 |
Correct |
60 ms |
5604 KB |
Output is correct |
47 |
Correct |
152 ms |
5608 KB |
Output is correct |
48 |
Correct |
226 ms |
5608 KB |
Output is correct |
49 |
Correct |
73 ms |
5608 KB |
Output is correct |
50 |
Partially correct |
285 ms |
5608 KB |
Partially correct - number of queries: 5231 |
51 |
Correct |
145 ms |
5608 KB |
Output is correct |
52 |
Correct |
71 ms |
5608 KB |
Output is correct |
53 |
Correct |
157 ms |
5608 KB |
Output is correct |
54 |
Correct |
149 ms |
5608 KB |
Output is correct |
55 |
Correct |
62 ms |
5608 KB |
Output is correct |
56 |
Partially correct |
291 ms |
5608 KB |
Partially correct - number of queries: 5231 |
57 |
Correct |
195 ms |
5608 KB |
Output is correct |
58 |
Correct |
233 ms |
5608 KB |
Output is correct |
59 |
Correct |
219 ms |
5608 KB |
Output is correct |
60 |
Correct |
172 ms |
5608 KB |
Output is correct |
61 |
Correct |
148 ms |
5608 KB |
Output is correct |
62 |
Correct |
72 ms |
5608 KB |
Output is correct |
63 |
Correct |
152 ms |
5608 KB |
Output is correct |
64 |
Correct |
103 ms |
5608 KB |
Output is correct |
65 |
Correct |
96 ms |
5608 KB |
Output is correct |
66 |
Correct |
64 ms |
5608 KB |
Output is correct |
67 |
Correct |
69 ms |
5608 KB |
Output is correct |
68 |
Correct |
80 ms |
5608 KB |
Output is correct |
69 |
Correct |
66 ms |
5608 KB |
Output is correct |
70 |
Correct |
58 ms |
5608 KB |
Output is correct |
71 |
Partially correct |
291 ms |
5608 KB |
Partially correct - number of queries: 5229 |
72 |
Correct |
186 ms |
5608 KB |
Output is correct |
73 |
Partially correct |
275 ms |
5608 KB |
Partially correct - number of queries: 5166 |
74 |
Partially correct |
294 ms |
5608 KB |
Partially correct - number of queries: 5193 |
75 |
Correct |
134 ms |
5608 KB |
Output is correct |
76 |
Correct |
278 ms |
5608 KB |
Output is correct |
77 |
Partially correct |
286 ms |
5608 KB |
Partially correct - number of queries: 5320 |
78 |
Correct |
199 ms |
5608 KB |
Output is correct |
79 |
Correct |
291 ms |
5608 KB |
Output is correct |
80 |
Partially correct |
271 ms |
5608 KB |
Partially correct - number of queries: 5322 |
81 |
Partially correct |
366 ms |
5608 KB |
Partially correct - number of queries: 5331 |
82 |
Partially correct |
344 ms |
5608 KB |
Partially correct - number of queries: 5301 |
83 |
Correct |
131 ms |
5608 KB |
Output is correct |
84 |
Correct |
281 ms |
5608 KB |
Output is correct |
85 |
Partially correct |
280 ms |
5608 KB |
Partially correct - number of queries: 5334 |
86 |
Correct |
120 ms |
5608 KB |
Output is correct |
87 |
Correct |
129 ms |
5608 KB |
Output is correct |
88 |
Correct |
115 ms |
5608 KB |
Output is correct |
89 |
Correct |
117 ms |
5608 KB |
Output is correct |
90 |
Correct |
125 ms |
5608 KB |
Output is correct |
91 |
Correct |
115 ms |
5608 KB |
Output is correct |
92 |
Correct |
109 ms |
5608 KB |
Output is correct |
93 |
Correct |
151 ms |
5608 KB |
Output is correct |
94 |
Correct |
208 ms |
5608 KB |
Output is correct |
95 |
Correct |
179 ms |
5608 KB |
Output is correct |
96 |
Correct |
156 ms |
5608 KB |
Output is correct |
97 |
Correct |
124 ms |
5608 KB |
Output is correct |