#include "prize.h"
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int maxn = 200100;
bool visited[maxn];
int q[maxn][2];
int max_sum, ind;
P query(int i) {
if(visited[i]) return {q[i][0], q[i][1]};
visited[i] = true;
vector<int>curr = ask(i);
q[i][0] = curr[0];
q[i][1] = curr[1];
return {q[i][0], q[i][1]};
}
int sum(int i) {
query(i);
return q[i][0] + q[i][1];
}
void solve(int l, int r) {
//cout<<l<<" "<<r<<"\n";
if(l > r || ind != -1) return;
P ql = query(l);
P qr = query(r);
if(ql.first + ql.second == 0) {
ind = l;
return;
}
if(qr.first + qr.second == 0) {
ind = r;
return;
}
if(ql.first + ql.second != max_sum) {
solve(l+1, r);
return;
}
if(qr.first + qr.second != max_sum) {
solve(l, r-1);
return;
}
int between = qr.first - ql.first;
if(between == 0) return;
int mid = (l + r) / 2;
solve(l, mid);
solve(mid+1, r);
}
int find_best(int n) {
ind = -1;
for(int i=0;i<min(n, 500);i++) {
if(sum(i) == 0) return i;
max_sum = max(max_sum, sum(i));
} //max_sum = 1;
solve(0, n-1);
return ind;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
392 KB |
Output is correct |
2 |
Correct |
8 ms |
388 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
396 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
10 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
392 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
392 KB |
Output is correct |
8 |
Correct |
3 ms |
400 KB |
Output is correct |
9 |
Correct |
6 ms |
328 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
12 ms |
760 KB |
Output is correct |
12 |
Correct |
7 ms |
376 KB |
Output is correct |
13 |
Correct |
7 ms |
1120 KB |
Output is correct |
14 |
Correct |
10 ms |
376 KB |
Output is correct |
15 |
Correct |
32 ms |
504 KB |
Output is correct |
16 |
Partially correct |
70 ms |
1792 KB |
Partially correct - number of queries: 6682 |
17 |
Correct |
21 ms |
408 KB |
Output is correct |
18 |
Partially correct |
40 ms |
2080 KB |
Partially correct - number of queries: 8002 |
19 |
Correct |
3 ms |
524 KB |
Output is correct |
20 |
Correct |
16 ms |
652 KB |
Output is correct |
21 |
Correct |
33 ms |
888 KB |
Output is correct |
22 |
Correct |
9 ms |
456 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
26 ms |
1204 KB |
Output is correct |
26 |
Correct |
31 ms |
1260 KB |
Output is correct |
27 |
Correct |
7 ms |
404 KB |
Output is correct |
28 |
Partially correct |
41 ms |
1784 KB |
Partially correct - number of queries: 6933 |
29 |
Partially correct |
20 ms |
1704 KB |
Partially correct - number of queries: 5438 |
30 |
Partially correct |
68 ms |
2080 KB |
Partially correct - number of queries: 7955 |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
13 ms |
828 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
14 ms |
864 KB |
Output is correct |
35 |
Correct |
10 ms |
552 KB |
Output is correct |
36 |
Correct |
14 ms |
716 KB |
Output is correct |
37 |
Correct |
7 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
396 KB |
Output is correct |
39 |
Correct |
22 ms |
1016 KB |
Output is correct |
40 |
Partially correct |
64 ms |
1984 KB |
Partially correct - number of queries: 6998 |
41 |
Correct |
47 ms |
1276 KB |
Output is correct |
42 |
Correct |
47 ms |
1272 KB |
Output is correct |
43 |
Correct |
44 ms |
1272 KB |
Output is correct |
44 |
Correct |
26 ms |
916 KB |
Output is correct |
45 |
Correct |
11 ms |
892 KB |
Output is correct |
46 |
Correct |
3 ms |
544 KB |
Output is correct |
47 |
Correct |
37 ms |
1024 KB |
Output is correct |
48 |
Partially correct |
41 ms |
1656 KB |
Partially correct - number of queries: 5826 |
49 |
Correct |
6 ms |
484 KB |
Output is correct |
50 |
Partially correct |
75 ms |
1960 KB |
Partially correct - number of queries: 7960 |
51 |
Correct |
20 ms |
1024 KB |
Output is correct |
52 |
Correct |
8 ms |
304 KB |
Output is correct |
53 |
Correct |
12 ms |
632 KB |
Output is correct |
54 |
Correct |
14 ms |
1116 KB |
Output is correct |
55 |
Correct |
6 ms |
256 KB |
Output is correct |
56 |
Partially correct |
50 ms |
2040 KB |
Partially correct - number of queries: 8048 |
57 |
Partially correct |
38 ms |
1528 KB |
Partially correct - number of queries: 5799 |
58 |
Partially correct |
53 ms |
1592 KB |
Partially correct - number of queries: 5858 |
59 |
Correct |
24 ms |
1368 KB |
Output is correct |
60 |
Correct |
46 ms |
1236 KB |
Output is correct |
61 |
Correct |
9 ms |
532 KB |
Output is correct |
62 |
Correct |
5 ms |
376 KB |
Output is correct |
63 |
Correct |
6 ms |
632 KB |
Output is correct |
64 |
Correct |
7 ms |
428 KB |
Output is correct |
65 |
Correct |
6 ms |
256 KB |
Output is correct |
66 |
Correct |
6 ms |
256 KB |
Output is correct |
67 |
Correct |
7 ms |
256 KB |
Output is correct |
68 |
Correct |
3 ms |
524 KB |
Output is correct |
69 |
Correct |
4 ms |
312 KB |
Output is correct |
70 |
Correct |
6 ms |
256 KB |
Output is correct |
71 |
Partially correct |
67 ms |
1972 KB |
Partially correct - number of queries: 8601 |
72 |
Correct |
9 ms |
1016 KB |
Output is correct |
73 |
Partially correct |
98 ms |
2040 KB |
Partially correct - number of queries: 8496 |
74 |
Partially correct |
62 ms |
1972 KB |
Partially correct - number of queries: 8541 |
75 |
Correct |
4 ms |
692 KB |
Output is correct |
76 |
Partially correct |
34 ms |
2040 KB |
Partially correct - number of queries: 7521 |
77 |
Partially correct |
58 ms |
2060 KB |
Partially correct - number of queries: 7787 |
78 |
Correct |
12 ms |
1016 KB |
Output is correct |
79 |
Correct |
32 ms |
1948 KB |
Output is correct |
80 |
Partially correct |
75 ms |
2136 KB |
Partially correct - number of queries: 7853 |
81 |
Partially correct |
33 ms |
2148 KB |
Partially correct - number of queries: 7749 |
82 |
Partially correct |
61 ms |
1960 KB |
Partially correct - number of queries: 7773 |
83 |
Correct |
10 ms |
632 KB |
Output is correct |
84 |
Partially correct |
39 ms |
2040 KB |
Partially correct - number of queries: 6361 |
85 |
Partially correct |
82 ms |
1984 KB |
Partially correct - number of queries: 7690 |
86 |
Correct |
7 ms |
384 KB |
Output is correct |
87 |
Correct |
3 ms |
396 KB |
Output is correct |
88 |
Correct |
7 ms |
384 KB |
Output is correct |
89 |
Correct |
5 ms |
384 KB |
Output is correct |
90 |
Correct |
5 ms |
384 KB |
Output is correct |
91 |
Correct |
3 ms |
412 KB |
Output is correct |
92 |
Correct |
5 ms |
384 KB |
Output is correct |
93 |
Correct |
14 ms |
760 KB |
Output is correct |
94 |
Correct |
11 ms |
1016 KB |
Output is correct |
95 |
Correct |
6 ms |
904 KB |
Output is correct |
96 |
Correct |
11 ms |
896 KB |
Output is correct |
97 |
Correct |
5 ms |
384 KB |
Output is correct |