#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
pii memo[200005];
pii query(int p) {
if(memo[p] != pii{ -1, -1 }) return memo[p];
vector<int> res = ask(p);
return memo[p] = { res[0], res[1] };
}
int sum(int p) { return query(p).first + query(p).second; }
int L(int p) { return query(p).first; }
int R(int p) { return query(p).second; }
int find_best(int n) {
//da se iskoristat 2ki?????
for(int i=0; i<n; i++) memo[i] = { -1, -1 };
int curr = -1, mx = 0;
set<int> s;
for(int i=0; i<min(480, n); i++) {
mx = max(mx, sum(i));
if(sum(i) == 0) return i;
}
int R = n-1, cnt = 1;
for(int i=0; i<min(480, n); i++) {
if(sum(i) == 1) {
if(L(i) == 1) {
R = i;
break;
}
}
if(sum(i) != mx) {
curr = i;
cnt++;
}
}
for(int i=cnt; i<=mx; i++) {
int l=curr+1, r=R, pos=n-1;
while(l <= r) {
int mid = (l + r) / 2;
if(sum(mid) == 0) return mid;
if(sum(mid) == mx) {
if(L(mid) >= i) pos = mid, r = mid - 1;
else l = mid + 1;
} else {
if(sum(mid) == 1 && L(mid) == 1)
R = min(R, mid - 1);
pos = mid;
r = mid - 1;
}
}
curr = pos;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1880 KB |
Output is correct |
2 |
Correct |
3 ms |
1880 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1880 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
2 ms |
1880 KB |
Output is correct |
7 |
Correct |
4 ms |
1880 KB |
Output is correct |
8 |
Correct |
3 ms |
1880 KB |
Output is correct |
9 |
Correct |
3 ms |
2136 KB |
Output is correct |
10 |
Correct |
3 ms |
1880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
3 ms |
1880 KB |
Output is correct |
3 |
Correct |
4 ms |
2132 KB |
Output is correct |
4 |
Correct |
3 ms |
1880 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
1 ms |
1880 KB |
Output is correct |
7 |
Correct |
3 ms |
1880 KB |
Output is correct |
8 |
Correct |
3 ms |
2132 KB |
Output is correct |
9 |
Correct |
4 ms |
1880 KB |
Output is correct |
10 |
Correct |
3 ms |
1880 KB |
Output is correct |
11 |
Correct |
4 ms |
1880 KB |
Output is correct |
12 |
Correct |
3 ms |
1880 KB |
Output is correct |
13 |
Correct |
6 ms |
1880 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
9 ms |
1880 KB |
Output is correct |
16 |
Partially correct |
29 ms |
2136 KB |
Partially correct - number of queries: 6966 |
17 |
Correct |
3 ms |
1880 KB |
Output is correct |
18 |
Partially correct |
39 ms |
1880 KB |
Partially correct - number of queries: 8073 |
19 |
Correct |
3 ms |
1880 KB |
Output is correct |
20 |
Correct |
11 ms |
1112 KB |
Output is correct |
21 |
Correct |
18 ms |
1880 KB |
Output is correct |
22 |
Correct |
5 ms |
1880 KB |
Output is correct |
23 |
Correct |
3 ms |
1876 KB |
Output is correct |
24 |
Correct |
3 ms |
1880 KB |
Output is correct |
25 |
Correct |
18 ms |
1880 KB |
Output is correct |
26 |
Correct |
24 ms |
1880 KB |
Output is correct |
27 |
Correct |
3 ms |
2136 KB |
Output is correct |
28 |
Partially correct |
36 ms |
1880 KB |
Partially correct - number of queries: 7663 |
29 |
Partially correct |
25 ms |
1880 KB |
Partially correct - number of queries: 5923 |
30 |
Partially correct |
36 ms |
1880 KB |
Partially correct - number of queries: 8011 |
31 |
Correct |
3 ms |
1880 KB |
Output is correct |
32 |
Correct |
5 ms |
1880 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
12 ms |
1880 KB |
Output is correct |
35 |
Correct |
4 ms |
1880 KB |
Output is correct |
36 |
Correct |
11 ms |
1880 KB |
Output is correct |
37 |
Correct |
4 ms |
1880 KB |
Output is correct |
38 |
Correct |
3 ms |
1880 KB |
Output is correct |
39 |
Correct |
16 ms |
1880 KB |
Output is correct |
40 |
Partially correct |
35 ms |
1880 KB |
Partially correct - number of queries: 6938 |
41 |
Partially correct |
22 ms |
1880 KB |
Partially correct - number of queries: 5045 |
42 |
Partially correct |
26 ms |
1880 KB |
Partially correct - number of queries: 5045 |
43 |
Correct |
23 ms |
1880 KB |
Output is correct |
44 |
Correct |
15 ms |
1880 KB |
Output is correct |
45 |
Correct |
14 ms |
1876 KB |
Output is correct |
46 |
Correct |
3 ms |
1880 KB |
Output is correct |
47 |
Correct |
17 ms |
1880 KB |
Output is correct |
48 |
Partially correct |
29 ms |
1880 KB |
Partially correct - number of queries: 6113 |
49 |
Correct |
5 ms |
1880 KB |
Output is correct |
50 |
Partially correct |
39 ms |
1880 KB |
Partially correct - number of queries: 8065 |
51 |
Correct |
20 ms |
1880 KB |
Output is correct |
52 |
Correct |
4 ms |
1880 KB |
Output is correct |
53 |
Correct |
4 ms |
1880 KB |
Output is correct |
54 |
Correct |
16 ms |
1880 KB |
Output is correct |
55 |
Correct |
3 ms |
1880 KB |
Output is correct |
56 |
Partially correct |
38 ms |
1880 KB |
Partially correct - number of queries: 8073 |
57 |
Partially correct |
25 ms |
1880 KB |
Partially correct - number of queries: 6021 |
58 |
Partially correct |
29 ms |
2136 KB |
Partially correct - number of queries: 6089 |
59 |
Partially correct |
26 ms |
1880 KB |
Partially correct - number of queries: 5041 |
60 |
Correct |
18 ms |
1880 KB |
Output is correct |
61 |
Correct |
4 ms |
1880 KB |
Output is correct |
62 |
Correct |
3 ms |
1880 KB |
Output is correct |
63 |
Correct |
5 ms |
1880 KB |
Output is correct |
64 |
Correct |
4 ms |
1880 KB |
Output is correct |
65 |
Correct |
3 ms |
1880 KB |
Output is correct |
66 |
Correct |
6 ms |
2136 KB |
Output is correct |
67 |
Correct |
3 ms |
1880 KB |
Output is correct |
68 |
Correct |
3 ms |
1880 KB |
Output is correct |
69 |
Correct |
5 ms |
1880 KB |
Output is correct |
70 |
Correct |
3 ms |
1880 KB |
Output is correct |
71 |
Partially correct |
37 ms |
1880 KB |
Partially correct - number of queries: 8250 |
72 |
Correct |
5 ms |
1880 KB |
Output is correct |
73 |
Partially correct |
30 ms |
1880 KB |
Partially correct - number of queries: 8139 |
74 |
Partially correct |
46 ms |
1880 KB |
Partially correct - number of queries: 8199 |
75 |
Correct |
3 ms |
1880 KB |
Output is correct |
76 |
Partially correct |
36 ms |
1880 KB |
Partially correct - number of queries: 7096 |
77 |
Partially correct |
44 ms |
1880 KB |
Partially correct - number of queries: 8116 |
78 |
Correct |
5 ms |
1880 KB |
Output is correct |
79 |
Correct |
19 ms |
1880 KB |
Output is correct |
80 |
Partially correct |
39 ms |
2076 KB |
Partially correct - number of queries: 8106 |
81 |
Partially correct |
38 ms |
1880 KB |
Partially correct - number of queries: 8103 |
82 |
Partially correct |
34 ms |
1880 KB |
Partially correct - number of queries: 8017 |
83 |
Correct |
3 ms |
1880 KB |
Output is correct |
84 |
Partially correct |
43 ms |
1880 KB |
Partially correct - number of queries: 6695 |
85 |
Partially correct |
50 ms |
1880 KB |
Partially correct - number of queries: 8040 |
86 |
Correct |
3 ms |
1880 KB |
Output is correct |
87 |
Correct |
3 ms |
1880 KB |
Output is correct |
88 |
Correct |
3 ms |
1880 KB |
Output is correct |
89 |
Correct |
4 ms |
1880 KB |
Output is correct |
90 |
Correct |
3 ms |
1880 KB |
Output is correct |
91 |
Correct |
3 ms |
1880 KB |
Output is correct |
92 |
Correct |
4 ms |
1880 KB |
Output is correct |
93 |
Correct |
5 ms |
1880 KB |
Output is correct |
94 |
Correct |
6 ms |
1880 KB |
Output is correct |
95 |
Correct |
5 ms |
1880 KB |
Output is correct |
96 |
Correct |
5 ms |
1880 KB |
Output is correct |
97 |
Correct |
3 ms |
1880 KB |
Output is correct |