#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
using vi = vector<int>;
int N;
int lol = 0;
int isLol(const vi &a) {
return a[0] + a[1] == lol;
}
int get(int l, int r, int kiek, int kair, int des) {
// int sqr = (int)sqrt(r - l + 1);
// printf("l = %d, r = %d, kiek = %d\n", l, r, kiek);
int m = (l + r) / 2;
if (kiek <= 0) return -1;
if (l > r) return -1;
// int st = max(l, m - kiek / 2 - 5);
// ieskom did des [1]
vi viso(2, 0);
int ind = -1;
vi ans = ask(m);
if (ans[0] == ans[1] and ans[0] == 0)
return m;
if (isLol(ans)) {
ind = m;
viso = ans;
int left = get(l, ind - 1, viso[0] - kair, kair, viso[1]);
int right = get(ind + 1, r, viso[1] - des, viso[0], des);
if (left != -1) return left;
else return right;
}
int k = 1;
for (int i = 1; ind == -1 and (l <= (m - i) or (m + i) <= r); ++i)
{
if (l <= (m - i)) {
ans = ask(m - i);
// printf("askinu %d\n", m - i);
if (ans[0] == ans[1] and ans[0] == 0)
return m - i;
if (!isLol(ans)) {
k++;
} else {
ind = m - i;
viso = ans;
int left = get(l, ind - 1, viso[0] - kair, kair, viso[1]);
int right = get(m + i, r, viso[1] - des - k, viso[0] + k, des);
if (left != -1) return left;
else return right;
}
}
if ((m + i) <= r) {
ans = ask(m + i);
// printf("askinu %d\n", m + i);
if (ans[0] == ans[1] and ans[0] == 0)
return m + i;
if (!isLol(ans)) {
k++;
} else {
ind = m + i;
viso = ans;
int left = get(l, m - i - 1, viso[0] - kair - k, kair, viso[1] + k);
int right = get(ind + 1, r, viso[1] - des, viso[0], des);
if (left != -1) return left;
else return right;
}
}
}
// printf("l = %d, r = %d, kiek = %d, ind = %d, viso = %d %d, kair = %d, des = %d\n",
// l, r, kiek, ind, viso[0], viso[1], kair, des);
return -1;
// if (ind == -1) return -1;
// ind is lol
// int left = get(l, ind - 1, viso[0] - kair, kair, viso[1]);
// int right = get(ind + 1, r, viso[1] - des, viso[0], des);
// if (left != -1) return left;
// else return right;
}
int find_best(int n) {
N = n;
// if (n <= 5000) {
// for (int i = 0; i < n; ++i)
// {
// vi ans = ask(i);
// if (ans[0] == ans[1] and ans[0] == 0)
// return i;
// }
// }
vi viso(2, 0);
int ind = 0;
for (int i = 0; i < 475; ++i) {
vi ans = ask(i);
if (ans[0] == ans[1] and ans[0] == 0)
return i;
if (ans[0] + ans[1] >= viso[0] + viso[1]) {
ind = i;
viso = ans;
}
}
// printf("viso = %d %d\n", viso[0], viso[1]);
lol = viso[0] + viso[1];
return get(ind + 1, n - 1, viso[1], viso[0], 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
11 ms |
256 KB |
Output is correct |
15 |
Correct |
49 ms |
256 KB |
Output is correct |
16 |
Correct |
49 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
42 ms |
256 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
27 ms |
256 KB |
Output is correct |
21 |
Correct |
43 ms |
256 KB |
Output is correct |
22 |
Correct |
46 ms |
256 KB |
Output is correct |
23 |
Correct |
8 ms |
256 KB |
Output is correct |
24 |
Correct |
12 ms |
256 KB |
Output is correct |
25 |
Correct |
55 ms |
256 KB |
Output is correct |
26 |
Correct |
40 ms |
288 KB |
Output is correct |
27 |
Correct |
9 ms |
256 KB |
Output is correct |
28 |
Correct |
32 ms |
256 KB |
Output is correct |
29 |
Correct |
37 ms |
256 KB |
Output is correct |
30 |
Correct |
57 ms |
416 KB |
Output is correct |
31 |
Correct |
5 ms |
256 KB |
Output is correct |
32 |
Correct |
9 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
51 ms |
256 KB |
Output is correct |
35 |
Correct |
8 ms |
256 KB |
Output is correct |
36 |
Correct |
25 ms |
384 KB |
Output is correct |
37 |
Correct |
12 ms |
256 KB |
Output is correct |
38 |
Correct |
7 ms |
376 KB |
Output is correct |
39 |
Correct |
41 ms |
360 KB |
Output is correct |
40 |
Correct |
54 ms |
256 KB |
Output is correct |
41 |
Correct |
40 ms |
256 KB |
Output is correct |
42 |
Correct |
45 ms |
256 KB |
Output is correct |
43 |
Correct |
53 ms |
384 KB |
Output is correct |
44 |
Correct |
42 ms |
256 KB |
Output is correct |
45 |
Correct |
53 ms |
256 KB |
Output is correct |
46 |
Correct |
5 ms |
256 KB |
Output is correct |
47 |
Correct |
48 ms |
256 KB |
Output is correct |
48 |
Correct |
26 ms |
368 KB |
Output is correct |
49 |
Correct |
58 ms |
256 KB |
Output is correct |
50 |
Correct |
43 ms |
256 KB |
Output is correct |
51 |
Correct |
46 ms |
256 KB |
Output is correct |
52 |
Correct |
43 ms |
256 KB |
Output is correct |
53 |
Correct |
3 ms |
376 KB |
Output is correct |
54 |
Correct |
54 ms |
256 KB |
Output is correct |
55 |
Correct |
4 ms |
256 KB |
Output is correct |
56 |
Correct |
43 ms |
256 KB |
Output is correct |
57 |
Correct |
39 ms |
256 KB |
Output is correct |
58 |
Correct |
50 ms |
256 KB |
Output is correct |
59 |
Correct |
45 ms |
256 KB |
Output is correct |
60 |
Correct |
57 ms |
256 KB |
Output is correct |
61 |
Correct |
8 ms |
256 KB |
Output is correct |
62 |
Correct |
8 ms |
256 KB |
Output is correct |
63 |
Correct |
6 ms |
256 KB |
Output is correct |
64 |
Correct |
5 ms |
256 KB |
Output is correct |
65 |
Correct |
5 ms |
256 KB |
Output is correct |
66 |
Correct |
8 ms |
256 KB |
Output is correct |
67 |
Correct |
7 ms |
256 KB |
Output is correct |
68 |
Correct |
4 ms |
256 KB |
Output is correct |
69 |
Correct |
5 ms |
380 KB |
Output is correct |
70 |
Correct |
6 ms |
256 KB |
Output is correct |
71 |
Partially correct |
41 ms |
256 KB |
Partially correct - number of queries: 5234 |
72 |
Correct |
10 ms |
256 KB |
Output is correct |
73 |
Partially correct |
49 ms |
256 KB |
Partially correct - number of queries: 5171 |
74 |
Partially correct |
62 ms |
256 KB |
Partially correct - number of queries: 5198 |
75 |
Correct |
7 ms |
256 KB |
Output is correct |
76 |
Correct |
39 ms |
256 KB |
Output is correct |
77 |
Correct |
46 ms |
256 KB |
Output is correct |
78 |
Correct |
9 ms |
256 KB |
Output is correct |
79 |
Correct |
22 ms |
256 KB |
Output is correct |
80 |
Correct |
59 ms |
256 KB |
Output is correct |
81 |
Correct |
45 ms |
256 KB |
Output is correct |
82 |
Correct |
43 ms |
256 KB |
Output is correct |
83 |
Correct |
3 ms |
384 KB |
Output is correct |
84 |
Correct |
45 ms |
256 KB |
Output is correct |
85 |
Correct |
42 ms |
256 KB |
Output is correct |
86 |
Correct |
7 ms |
256 KB |
Output is correct |
87 |
Correct |
7 ms |
256 KB |
Output is correct |
88 |
Correct |
5 ms |
256 KB |
Output is correct |
89 |
Correct |
7 ms |
256 KB |
Output is correct |
90 |
Correct |
5 ms |
256 KB |
Output is correct |
91 |
Correct |
5 ms |
372 KB |
Output is correct |
92 |
Correct |
5 ms |
376 KB |
Output is correct |
93 |
Correct |
8 ms |
256 KB |
Output is correct |
94 |
Correct |
8 ms |
256 KB |
Output is correct |
95 |
Correct |
8 ms |
256 KB |
Output is correct |
96 |
Correct |
8 ms |
256 KB |
Output is correct |
97 |
Correct |
5 ms |
256 KB |
Output is correct |