#include "prize.h"
#include <cstdlib>
int recursive_find_best(int n, int m, int s, int e, int xl, int xr) {
std::vector<int> r, r0;
if (xl + xr >= m) return -1;
if (e - s < 2) {
for (int i = s; i <= e; ++i) {
r = ask(i);
if (r[0] + r[1] == 0) return i;
}
return -1;
}
int midl = (s + e) / 2, midr = (s + e) / 2;
r0 = ask(midl);
if (r0[0] + r0[1] == 0) return midl;
for (r = r0, --midl; r[0] + r[1] < m && midl > s; --midl) {
r = ask(midl);
if (r[0] + r[1] == 0) return midl;
}
int ans = recursive_find_best(n, m, s, midl, xl, r[1]);
if (ans >= 0) return ans;
for (r = r0, ++midr; r[0] + r[1] < m && midr < e; ++midr) {
r = ask(midr);
if (r[0] + r[1] == 0) return midr;
}
return recursive_find_best(n, m, midr, e, r[0], xr);
}
int find_best(int n) {
int m = 0;
for (int i = 0; i < 250; ++i) {
std::vector<int> r = ask(std::rand() % n);
if (r[0] + r[1] > m) m = r[0] + r[1];
}
return recursive_find_best(n, m, 0, n - 1, 0, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
540 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
432 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
24 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
21 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
9 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
14 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
28 ms |
344 KB |
Output is correct |
29 |
Correct |
16 ms |
344 KB |
Output is correct |
30 |
Correct |
23 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
11 ms |
344 KB |
Output is correct |
35 |
Correct |
3 ms |
344 KB |
Output is correct |
36 |
Correct |
9 ms |
344 KB |
Output is correct |
37 |
Correct |
3 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
14 ms |
684 KB |
Output is correct |
40 |
Correct |
23 ms |
344 KB |
Output is correct |
41 |
Correct |
11 ms |
344 KB |
Output is correct |
42 |
Correct |
13 ms |
344 KB |
Output is correct |
43 |
Correct |
17 ms |
344 KB |
Output is correct |
44 |
Correct |
8 ms |
684 KB |
Output is correct |
45 |
Correct |
7 ms |
344 KB |
Output is correct |
46 |
Correct |
2 ms |
344 KB |
Output is correct |
47 |
Correct |
10 ms |
344 KB |
Output is correct |
48 |
Correct |
17 ms |
344 KB |
Output is correct |
49 |
Correct |
2 ms |
344 KB |
Output is correct |
50 |
Correct |
24 ms |
344 KB |
Output is correct |
51 |
Correct |
13 ms |
344 KB |
Output is correct |
52 |
Correct |
2 ms |
344 KB |
Output is correct |
53 |
Correct |
3 ms |
344 KB |
Output is correct |
54 |
Correct |
12 ms |
344 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
19 ms |
344 KB |
Output is correct |
57 |
Correct |
10 ms |
344 KB |
Output is correct |
58 |
Correct |
11 ms |
344 KB |
Output is correct |
59 |
Correct |
13 ms |
344 KB |
Output is correct |
60 |
Correct |
12 ms |
344 KB |
Output is correct |
61 |
Correct |
2 ms |
344 KB |
Output is correct |
62 |
Correct |
2 ms |
344 KB |
Output is correct |
63 |
Correct |
3 ms |
596 KB |
Output is correct |
64 |
Correct |
2 ms |
344 KB |
Output is correct |
65 |
Correct |
2 ms |
344 KB |
Output is correct |
66 |
Correct |
4 ms |
344 KB |
Output is correct |
67 |
Correct |
2 ms |
344 KB |
Output is correct |
68 |
Correct |
4 ms |
344 KB |
Output is correct |
69 |
Correct |
5 ms |
344 KB |
Output is correct |
70 |
Correct |
2 ms |
340 KB |
Output is correct |
71 |
Correct |
26 ms |
344 KB |
Output is correct |
72 |
Correct |
4 ms |
344 KB |
Output is correct |
73 |
Correct |
30 ms |
344 KB |
Output is correct |
74 |
Correct |
25 ms |
344 KB |
Output is correct |
75 |
Correct |
3 ms |
600 KB |
Output is correct |
76 |
Correct |
18 ms |
340 KB |
Output is correct |
77 |
Partially correct |
25 ms |
600 KB |
Partially correct - number of queries: 5002 |
78 |
Correct |
5 ms |
344 KB |
Output is correct |
79 |
Correct |
17 ms |
600 KB |
Output is correct |
80 |
Correct |
25 ms |
344 KB |
Output is correct |
81 |
Correct |
35 ms |
340 KB |
Output is correct |
82 |
Correct |
31 ms |
344 KB |
Output is correct |
83 |
Correct |
2 ms |
344 KB |
Output is correct |
84 |
Correct |
18 ms |
344 KB |
Output is correct |
85 |
Correct |
21 ms |
344 KB |
Output is correct |
86 |
Correct |
20 ms |
600 KB |
Output is correct |
87 |
Correct |
3 ms |
344 KB |
Output is correct |
88 |
Correct |
13 ms |
344 KB |
Output is correct |
89 |
Correct |
5 ms |
436 KB |
Output is correct |
90 |
Correct |
2 ms |
344 KB |
Output is correct |
91 |
Correct |
5 ms |
436 KB |
Output is correct |
92 |
Correct |
15 ms |
432 KB |
Output is correct |
93 |
Incorrect |
2 ms |
344 KB |
Integer -1 violates the range [0, 199999] |
94 |
Halted |
0 ms |
0 KB |
- |