#include "prize.h"
#include <map>
#include <random>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct infos {
int pos, left, right;
infos(int pos_, int left_, int right_) : pos(pos_), left(left_), right(right_) {};
};
mt19937 mt(1902272037);
int rand_rng(int l, int r) {
uniform_int_distribution<int> p(l, r - 1);
return p(mt);
}
vector<int> random_pos(int n, int m) {
vector<int> ans;
for(int i = 0; i < m; ++i) {
int x = -1;
while(x == -1 || find(ans.begin(), ans.end(), x) != ans.end()) {
x = rand_rng(0, n);
}
ans.push_back(x);
}
sort(ans.begin(), ans.end());
return ans;
}
int find_best(int n) {
vector<int> samples = random_pos(n, min(n, 5));
int all = 0;
for(int i : samples) {
vector<int> res = ask(i);
all = max(all, res[0] + res[1]);
}
vector<infos> v = { infos(-1, 0, all), infos(n, all, 0) };
vector<int> s;
while(true) {
int maxd = 0, ptr = -1, mrem = -1;
for(int i = 0; i < int(v.size()) - 1; ++i) {
int rem = v[i].right + v[i + 1].left - all;
rem -= lower_bound(s.begin(), s.end(), v[i + 1].pos) - lower_bound(s.begin(), s.end(), v[i].pos);
if(rem > 0 && v[i + 1].pos - v[i].pos > maxd) {
maxd = v[i + 1].pos - v[i].pos;
ptr = i;
mrem = rem;
}
}
if(ptr == -1) break;
if(maxd >= 2) {
int m = (v[ptr].pos + v[ptr + 1].pos) / 2;
vector<int> res = ask(m);
if(res[0] + res[1] == 0) return m;
if(res[0] + res[1] == all) {
v.insert(v.begin() + ptr + 1, infos(m, res[0], res[1]));
}
else {
--mrem;
s.push_back(m);
int cm = m - 1, flag = 0;
while(mrem > 0 && cm > v[ptr].pos) {
vector<int> res2 = ask(cm);
if(res2[0] + res2[1] == 0) return cm;
if(res2[0] + res2[1] == all) {
v.insert(v.begin() + ptr + 1, infos(cm, res2[0], res2[1]));
flag = 1;
break;
}
s.push_back(cm);
--mrem;
--cm;
}
cm = m + 1;
while(mrem > 0 && cm < v[ptr + 1].pos) {
vector<int> res2 = ask(cm);
if(res2[0] + res2[1] == 0) return cm;
if(res2[0] + res2[1] == all) {
v.insert(v.begin() + ptr + 1 + flag, infos(cm, res2[0], res2[1]));
break;
}
s.push_back(cm);
--mrem;
++cm;
}
sort(s.begin(), s.end());
}
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
396 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
304 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
308 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
304 KB |
Output is correct |
12 |
Correct |
6 ms |
324 KB |
Output is correct |
13 |
Correct |
6 ms |
408 KB |
Output is correct |
14 |
Correct |
13 ms |
256 KB |
Output is correct |
15 |
Correct |
132 ms |
432 KB |
Output is correct |
16 |
Correct |
164 ms |
504 KB |
Output is correct |
17 |
Correct |
211 ms |
412 KB |
Output is correct |
18 |
Correct |
98 ms |
428 KB |
Output is correct |
19 |
Correct |
145 ms |
412 KB |
Output is correct |
20 |
Correct |
79 ms |
536 KB |
Output is correct |
21 |
Correct |
113 ms |
320 KB |
Output is correct |
22 |
Correct |
120 ms |
424 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
316 KB |
Output is correct |
25 |
Correct |
181 ms |
376 KB |
Output is correct |
26 |
Correct |
202 ms |
416 KB |
Output is correct |
27 |
Correct |
3 ms |
256 KB |
Output is correct |
28 |
Correct |
54 ms |
452 KB |
Output is correct |
29 |
Correct |
123 ms |
468 KB |
Output is correct |
30 |
Correct |
111 ms |
448 KB |
Output is correct |
31 |
Correct |
76 ms |
384 KB |
Output is correct |
32 |
Correct |
7 ms |
312 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
54 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
412 KB |
Output is correct |
36 |
Correct |
200 ms |
492 KB |
Output is correct |
37 |
Correct |
7 ms |
252 KB |
Output is correct |
38 |
Correct |
3 ms |
256 KB |
Output is correct |
39 |
Correct |
222 ms |
468 KB |
Output is correct |
40 |
Correct |
158 ms |
332 KB |
Output is correct |
41 |
Correct |
199 ms |
432 KB |
Output is correct |
42 |
Correct |
196 ms |
644 KB |
Output is correct |
43 |
Correct |
91 ms |
404 KB |
Output is correct |
44 |
Correct |
193 ms |
532 KB |
Output is correct |
45 |
Correct |
240 ms |
544 KB |
Output is correct |
46 |
Correct |
187 ms |
508 KB |
Output is correct |
47 |
Correct |
213 ms |
532 KB |
Output is correct |
48 |
Correct |
204 ms |
448 KB |
Output is correct |
49 |
Correct |
55 ms |
464 KB |
Output is correct |
50 |
Correct |
243 ms |
376 KB |
Output is correct |
51 |
Correct |
231 ms |
512 KB |
Output is correct |
52 |
Correct |
230 ms |
508 KB |
Output is correct |
53 |
Correct |
3 ms |
256 KB |
Output is correct |
54 |
Correct |
139 ms |
404 KB |
Output is correct |
55 |
Correct |
241 ms |
392 KB |
Output is correct |
56 |
Correct |
249 ms |
384 KB |
Output is correct |
57 |
Correct |
141 ms |
400 KB |
Output is correct |
58 |
Correct |
112 ms |
432 KB |
Output is correct |
59 |
Correct |
162 ms |
492 KB |
Output is correct |
60 |
Correct |
97 ms |
376 KB |
Output is correct |
61 |
Correct |
3 ms |
304 KB |
Output is correct |
62 |
Correct |
2 ms |
384 KB |
Output is correct |
63 |
Correct |
2 ms |
384 KB |
Output is correct |
64 |
Correct |
4 ms |
384 KB |
Output is correct |
65 |
Correct |
3 ms |
256 KB |
Output is correct |
66 |
Incorrect |
7 ms |
312 KB |
Integer -1 violates the range [0, 199999] |
67 |
Halted |
0 ms |
0 KB |
- |