#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1 << 30)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 201111
#define SQRT 450
#define BUCKET 600
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int max_val;
int ans;
bool used[maxn];
vector<int> v[maxn];
vector<int> ASK(int x){
if(!used[x]){
v[x] = ask(x);
used[x] = 1;
}
return v[x];
}
void solve(int L, int D){
if(ans != -1 || L > D)
return;
int l = -1, d = -1;
vector<int> left, right;
for(int i = L; i <= D; i++){
left = ASK(i);
if(left[0] + left[1] == 0){
ans = i;
return;
}
if(left[0] + left[1] == max_val){
l = i;
break;
}
}
if(l == -1)
return;
for(int i = D; i > l; i--){
right = ASK(i);
if(right[0] + right[1] == 0){
ans = i;
return;
}
if(right[0] + right[1] == max_val){
d = i;
break;
}
}
if(d == -1)
return;
int num = left[1] - right[1];
if(num == 0)
return;
int mid = (l + d) / 2;
solve(l, mid);
solve(mid + 1, d);
}
int find_best(int n){
max_val = -1;
for(int i = 0; i < min(SQRT + 50, n); i++){
vector<int> ret = ASK(i);
max_val = max(max_val, ret[0] + ret[1]);
}
ans = -1;
for(int i = 0; i < maxn / BUCKET + 1; i++){
int l = i * BUCKET;
solve(l, min(n - 1, l + BUCKET - 1));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
5028 KB |
Output is correct |
2 |
Correct |
23 ms |
5188 KB |
Output is correct |
3 |
Correct |
14 ms |
5252 KB |
Output is correct |
4 |
Correct |
20 ms |
5304 KB |
Output is correct |
5 |
Correct |
17 ms |
5304 KB |
Output is correct |
6 |
Correct |
9 ms |
5304 KB |
Output is correct |
7 |
Correct |
13 ms |
5304 KB |
Output is correct |
8 |
Correct |
27 ms |
5304 KB |
Output is correct |
9 |
Correct |
17 ms |
5388 KB |
Output is correct |
10 |
Correct |
19 ms |
5400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5400 KB |
Output is correct |
2 |
Correct |
19 ms |
5400 KB |
Output is correct |
3 |
Correct |
14 ms |
5400 KB |
Output is correct |
4 |
Correct |
25 ms |
5688 KB |
Output is correct |
5 |
Correct |
17 ms |
5688 KB |
Output is correct |
6 |
Correct |
12 ms |
5688 KB |
Output is correct |
7 |
Correct |
23 ms |
5688 KB |
Output is correct |
8 |
Correct |
19 ms |
5688 KB |
Output is correct |
9 |
Correct |
20 ms |
5688 KB |
Output is correct |
10 |
Correct |
19 ms |
5688 KB |
Output is correct |
11 |
Correct |
12 ms |
5688 KB |
Output is correct |
12 |
Correct |
15 ms |
5688 KB |
Output is correct |
13 |
Correct |
30 ms |
5688 KB |
Output is correct |
14 |
Correct |
16 ms |
5688 KB |
Output is correct |
15 |
Correct |
24 ms |
5688 KB |
Output is correct |
16 |
Partially correct |
88 ms |
5688 KB |
Partially correct - number of queries: 6680 |
17 |
Correct |
15 ms |
5688 KB |
Output is correct |
18 |
Partially correct |
85 ms |
5720 KB |
Partially correct - number of queries: 7965 |
19 |
Correct |
11 ms |
5720 KB |
Output is correct |
20 |
Correct |
38 ms |
5720 KB |
Output is correct |
21 |
Correct |
41 ms |
5720 KB |
Output is correct |
22 |
Correct |
14 ms |
5720 KB |
Output is correct |
23 |
Correct |
17 ms |
5720 KB |
Output is correct |
24 |
Correct |
15 ms |
5720 KB |
Output is correct |
25 |
Correct |
34 ms |
5720 KB |
Output is correct |
26 |
Correct |
67 ms |
5720 KB |
Output is correct |
27 |
Correct |
16 ms |
5720 KB |
Output is correct |
28 |
Partially correct |
37 ms |
5720 KB |
Partially correct - number of queries: 6870 |
29 |
Partially correct |
51 ms |
5720 KB |
Partially correct - number of queries: 5528 |
30 |
Partially correct |
81 ms |
5720 KB |
Partially correct - number of queries: 7885 |
31 |
Correct |
9 ms |
5720 KB |
Output is correct |
32 |
Correct |
23 ms |
5720 KB |
Output is correct |
33 |
Correct |
9 ms |
5720 KB |
Output is correct |
34 |
Correct |
34 ms |
5720 KB |
Output is correct |
35 |
Correct |
18 ms |
5720 KB |
Output is correct |
36 |
Correct |
32 ms |
5720 KB |
Output is correct |
37 |
Correct |
11 ms |
5720 KB |
Output is correct |
38 |
Correct |
10 ms |
5720 KB |
Output is correct |
39 |
Correct |
37 ms |
5720 KB |
Output is correct |
40 |
Partially correct |
75 ms |
5720 KB |
Partially correct - number of queries: 6971 |
41 |
Correct |
59 ms |
5720 KB |
Output is correct |
42 |
Correct |
49 ms |
5720 KB |
Output is correct |
43 |
Correct |
51 ms |
5720 KB |
Output is correct |
44 |
Correct |
35 ms |
5720 KB |
Output is correct |
45 |
Correct |
21 ms |
5720 KB |
Output is correct |
46 |
Correct |
13 ms |
5720 KB |
Output is correct |
47 |
Correct |
22 ms |
5720 KB |
Output is correct |
48 |
Partially correct |
52 ms |
5720 KB |
Partially correct - number of queries: 5837 |
49 |
Correct |
19 ms |
5720 KB |
Output is correct |
50 |
Partially correct |
83 ms |
5720 KB |
Partially correct - number of queries: 7992 |
51 |
Correct |
30 ms |
5720 KB |
Output is correct |
52 |
Correct |
9 ms |
5720 KB |
Output is correct |
53 |
Correct |
24 ms |
5720 KB |
Output is correct |
54 |
Correct |
51 ms |
5720 KB |
Output is correct |
55 |
Correct |
16 ms |
5720 KB |
Output is correct |
56 |
Partially correct |
68 ms |
5720 KB |
Partially correct - number of queries: 8005 |
57 |
Partially correct |
38 ms |
5720 KB |
Partially correct - number of queries: 5780 |
58 |
Partially correct |
55 ms |
5720 KB |
Partially correct - number of queries: 5760 |
59 |
Correct |
72 ms |
5720 KB |
Output is correct |
60 |
Correct |
58 ms |
5720 KB |
Output is correct |
61 |
Correct |
24 ms |
5720 KB |
Output is correct |
62 |
Correct |
10 ms |
5720 KB |
Output is correct |
63 |
Correct |
15 ms |
5720 KB |
Output is correct |
64 |
Correct |
13 ms |
5720 KB |
Output is correct |
65 |
Correct |
25 ms |
5720 KB |
Output is correct |
66 |
Correct |
31 ms |
5720 KB |
Output is correct |
67 |
Correct |
27 ms |
5720 KB |
Output is correct |
68 |
Correct |
13 ms |
5720 KB |
Output is correct |
69 |
Correct |
31 ms |
5720 KB |
Output is correct |
70 |
Correct |
25 ms |
5720 KB |
Output is correct |
71 |
Partially correct |
93 ms |
5720 KB |
Partially correct - number of queries: 8438 |
72 |
Correct |
30 ms |
5720 KB |
Output is correct |
73 |
Partially correct |
55 ms |
5740 KB |
Partially correct - number of queries: 8340 |
74 |
Partially correct |
114 ms |
5740 KB |
Partially correct - number of queries: 8382 |
75 |
Correct |
27 ms |
5740 KB |
Output is correct |
76 |
Partially correct |
93 ms |
5740 KB |
Partially correct - number of queries: 7430 |
77 |
Partially correct |
79 ms |
5740 KB |
Partially correct - number of queries: 7687 |
78 |
Correct |
21 ms |
5740 KB |
Output is correct |
79 |
Correct |
53 ms |
5740 KB |
Output is correct |
80 |
Partially correct |
43 ms |
5740 KB |
Partially correct - number of queries: 7649 |
81 |
Partially correct |
80 ms |
5772 KB |
Partially correct - number of queries: 7665 |
82 |
Partially correct |
66 ms |
5772 KB |
Partially correct - number of queries: 7401 |
83 |
Correct |
16 ms |
5772 KB |
Output is correct |
84 |
Partially correct |
75 ms |
5772 KB |
Partially correct - number of queries: 6425 |
85 |
Partially correct |
59 ms |
5772 KB |
Partially correct - number of queries: 7531 |
86 |
Correct |
22 ms |
5772 KB |
Output is correct |
87 |
Correct |
22 ms |
5772 KB |
Output is correct |
88 |
Correct |
20 ms |
5772 KB |
Output is correct |
89 |
Correct |
21 ms |
5772 KB |
Output is correct |
90 |
Correct |
15 ms |
5772 KB |
Output is correct |
91 |
Correct |
22 ms |
5772 KB |
Output is correct |
92 |
Correct |
11 ms |
5772 KB |
Output is correct |
93 |
Correct |
23 ms |
5772 KB |
Output is correct |
94 |
Correct |
20 ms |
5772 KB |
Output is correct |
95 |
Correct |
18 ms |
5772 KB |
Output is correct |
96 |
Correct |
19 ms |
5772 KB |
Output is correct |
97 |
Correct |
23 ms |
5772 KB |
Output is correct |