#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> K(int i) {
return ask(i);
}
int find_best(int N) {
int lol = -1, ted = -1, cnt = 0, ono = 0;
vector<int> chuchu;
vector<vector<int>> a(472);
for (int i = 0; i < 472; i++) {
a[i] = K(i);
int s = a[i][0] + a[i][1];
if (s == 0) {
return i;
}
lol = max(lol, s);
}
for (int i = 0; i < 472; i++) {
int s = a[i][0] + a[i][1];
if (s < lol) {
cnt++;
if (s > ted) {
ted = s;
ono = 0;
chuchu = a[i];
} else if (s < ted) {
ono++;
}
}
}
int x = 472;
while (cnt < 25) {
vector<int> t = K(x);
int s = t[0] + t[1];
if (s == 0) {
return x;
}
if (s == lol) {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = K(mi);
if (v == t) {
lo = mi;
} else {
hi = mi - 1;
}
}
x = lo;
} else {
cnt++;
if (s > ted) {
ted = s;
ono = 0;
chuchu = t;
} else if (s < ted) {
ono++;
}
}
x++;
}
while (1) {
vector<int> t = K(x);
int s = t[0] + t[1];
if (s == 0) {
return x;
}
if (s < ted) {
x++;
ono++;
continue;
}
if (s == lol) {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = K(mi);
if (v[0] + v[1] == lol) {
int l = lo, r = mi;
bool f = 0;
while (l < r) {
int m = (l + r) / 2;
vector<int> u = K(m);
if (u[0] + u[1] == lol) {
if (u == v) {
r = m;
} else {
l = m + 1;
}
} else if (u[0] + u[1] == ted) {
if (chuchu[0] + ono == u[0]) {
lo = m;
l = m + 1;
} else {
f = 1;
hi = m - 1;
break;
}
} else {
f = 1;
hi = m - 1;
break;
}
}
if (!f) {
if (l == lo) {
lo = mi;
} else if (K(l - 1)[0] + K(l - 1)[1] == ted) {
if (chuchu[0] + ono == K(l - 1)[0]) {
lo = mi;
} else {
hi = mi - 1;
}
} else {
hi = mi - 1;
}
}
} else if (v[0] + v[1] == ted) {
if (chuchu[0] + ono == v[0]) {
lo = mi;
} else {
hi = mi - 1;
}
} else {
hi = mi - 1;
}
}
x = lo + 1;
} else {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = K(mi);
if (v == t) {
lo = mi;
} else if (v[0] + v[1] == lol) {
int l = lo + 1, r = mi;
bool f = 0;
while (l < r) {
int m = (l + r) / 2;
vector<int> u = K(m);
if (u[0] + u[1] == lol) {
if (u == v) {
r = m;
} else {
l = m + 1;
}
} else if (u[0] + u[1] == ted) {
if (t == u) {
lo = m;
l = m + 1;
} else {
f = 1;
hi = m - 1;
break;
}
} else {
f = 1;
hi = m - 1;
break;
}
}
if (!f) {
if (K(l - 1) == t) {
lo = mi;
} else {
hi = l - 2;
}
}
} else {
hi = mi - 1;
}
}
x = lo + 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
316 KB |
Output is correct |
4 |
Correct |
9 ms |
312 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
312 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
320 KB |
Output is correct |
4 |
Correct |
4 ms |
300 KB |
Output is correct |
5 |
Correct |
2 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
324 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
316 KB |
Output is correct |
14 |
Correct |
6 ms |
208 KB |
Output is correct |
15 |
Correct |
4 ms |
312 KB |
Output is correct |
16 |
Correct |
15 ms |
316 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
14 ms |
316 KB |
Output is correct |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
15 ms |
208 KB |
Output is correct |
21 |
Correct |
8 ms |
320 KB |
Output is correct |
22 |
Correct |
5 ms |
324 KB |
Output is correct |
23 |
Correct |
4 ms |
292 KB |
Output is correct |
24 |
Correct |
5 ms |
292 KB |
Output is correct |
25 |
Correct |
25 ms |
208 KB |
Output is correct |
26 |
Correct |
19 ms |
208 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
24 ms |
308 KB |
Output is correct |
29 |
Correct |
27 ms |
292 KB |
Output is correct |
30 |
Correct |
20 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
7 ms |
308 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
9 ms |
300 KB |
Output is correct |
35 |
Correct |
6 ms |
208 KB |
Output is correct |
36 |
Correct |
8 ms |
208 KB |
Output is correct |
37 |
Correct |
3 ms |
312 KB |
Output is correct |
38 |
Correct |
3 ms |
208 KB |
Output is correct |
39 |
Correct |
17 ms |
292 KB |
Output is correct |
40 |
Correct |
9 ms |
316 KB |
Output is correct |
41 |
Correct |
23 ms |
292 KB |
Output is correct |
42 |
Correct |
23 ms |
296 KB |
Output is correct |
43 |
Correct |
10 ms |
324 KB |
Output is correct |
44 |
Correct |
8 ms |
320 KB |
Output is correct |
45 |
Correct |
10 ms |
316 KB |
Output is correct |
46 |
Correct |
3 ms |
208 KB |
Output is correct |
47 |
Correct |
27 ms |
292 KB |
Output is correct |
48 |
Correct |
28 ms |
208 KB |
Output is correct |
49 |
Correct |
5 ms |
292 KB |
Output is correct |
50 |
Correct |
36 ms |
308 KB |
Output is correct |
51 |
Correct |
30 ms |
288 KB |
Output is correct |
52 |
Correct |
5 ms |
208 KB |
Output is correct |
53 |
Correct |
5 ms |
320 KB |
Output is correct |
54 |
Correct |
7 ms |
324 KB |
Output is correct |
55 |
Correct |
3 ms |
288 KB |
Output is correct |
56 |
Correct |
14 ms |
324 KB |
Output is correct |
57 |
Correct |
17 ms |
288 KB |
Output is correct |
58 |
Correct |
29 ms |
208 KB |
Output is correct |
59 |
Correct |
24 ms |
300 KB |
Output is correct |
60 |
Correct |
22 ms |
208 KB |
Output is correct |
61 |
Correct |
3 ms |
292 KB |
Output is correct |
62 |
Correct |
4 ms |
208 KB |
Output is correct |
63 |
Correct |
3 ms |
208 KB |
Output is correct |
64 |
Correct |
4 ms |
208 KB |
Output is correct |
65 |
Correct |
5 ms |
208 KB |
Output is correct |
66 |
Correct |
3 ms |
296 KB |
Output is correct |
67 |
Correct |
2 ms |
208 KB |
Output is correct |
68 |
Correct |
5 ms |
208 KB |
Output is correct |
69 |
Correct |
2 ms |
208 KB |
Output is correct |
70 |
Correct |
2 ms |
324 KB |
Output is correct |
71 |
Correct |
38 ms |
208 KB |
Output is correct |
72 |
Correct |
15 ms |
208 KB |
Output is correct |
73 |
Correct |
35 ms |
208 KB |
Output is correct |
74 |
Correct |
33 ms |
208 KB |
Output is correct |
75 |
Correct |
5 ms |
208 KB |
Output is correct |
76 |
Correct |
33 ms |
312 KB |
Output is correct |
77 |
Correct |
42 ms |
308 KB |
Output is correct |
78 |
Correct |
7 ms |
320 KB |
Output is correct |
79 |
Correct |
26 ms |
320 KB |
Output is correct |
80 |
Correct |
30 ms |
208 KB |
Output is correct |
81 |
Correct |
27 ms |
208 KB |
Output is correct |
82 |
Correct |
36 ms |
208 KB |
Output is correct |
83 |
Correct |
7 ms |
320 KB |
Output is correct |
84 |
Correct |
29 ms |
208 KB |
Output is correct |
85 |
Correct |
38 ms |
208 KB |
Output is correct |
86 |
Correct |
4 ms |
208 KB |
Output is correct |
87 |
Correct |
8 ms |
384 KB |
Output is correct |
88 |
Correct |
6 ms |
208 KB |
Output is correct |
89 |
Correct |
5 ms |
208 KB |
Output is correct |
90 |
Correct |
5 ms |
316 KB |
Output is correct |
91 |
Correct |
5 ms |
208 KB |
Output is correct |
92 |
Correct |
5 ms |
288 KB |
Output is correct |
93 |
Correct |
26 ms |
304 KB |
Output is correct |
94 |
Correct |
33 ms |
208 KB |
Output is correct |
95 |
Correct |
29 ms |
208 KB |
Output is correct |
96 |
Correct |
25 ms |
208 KB |
Output is correct |
97 |
Correct |
6 ms |
316 KB |
Output is correct |