#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef pair<int,int> pii;
int loli = 0;
vector<vector<int>>memo(222222,{-1,-1});
vector<int>glo;
vector<int>query(int x){
if(memo[x][0] == -1)memo[x] = ask(x);
glo = memo[x];
return memo[x];
}
int ans = 0;
void solve(int l,int r,int cntl,int cntr){
//cout<<l<<" "<<r<<" "<<cntl<<" "<<cntr<<'\n';
int mid = (l+r)/2;
int L = -1,R = -1;
for(int i=mid;i>=l;i--){
auto res = query(i);
if(glo[0]+res[1] == 0){
ans = i;
return;
}
if(glo[0]+glo[1] != loli)continue;
L = i;
break;
}
if(L!=-1){
auto t = query(L);
int x = mid-L;
if(t[0] - cntl)solve(l,L-1,cntl,t[1]);
if(t[1] - cntr - x)solve(mid+1,r,t[0] + x,cntr);
return;
}
///
for(int i=mid+1;i<=r;i++){
auto res = query(i);
if(res[0]+res[1] == 0){
ans = i;
return;
}
if(res[0]+res[1] != loli)continue;
R = i;
break;
}
if(R == -1)return;
auto t = query(R);
if(t[1] - cntr)solve(R+1,r,t[0],cntr);
}
int find_best(int n) {
int p = 0;
for(int i=0;i<min(n,477);i++){
vector<int>res = query(i);
if(res[0]+res[1] == 0)return i;
if(res[0]+res[1] > loli){
loli = res[0]+res[1];
p = i;
}
if(loli >= 27)break;
}
solve(p,n-1,p,0);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
12464 KB |
Output is correct |
2 |
Correct |
20 ms |
12456 KB |
Output is correct |
3 |
Correct |
14 ms |
12440 KB |
Output is correct |
4 |
Correct |
20 ms |
12484 KB |
Output is correct |
5 |
Correct |
14 ms |
12368 KB |
Output is correct |
6 |
Correct |
10 ms |
12368 KB |
Output is correct |
7 |
Correct |
19 ms |
12484 KB |
Output is correct |
8 |
Correct |
12 ms |
12484 KB |
Output is correct |
9 |
Correct |
15 ms |
12480 KB |
Output is correct |
10 |
Correct |
14 ms |
12372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12368 KB |
Output is correct |
2 |
Correct |
12 ms |
12484 KB |
Output is correct |
3 |
Correct |
12 ms |
12488 KB |
Output is correct |
4 |
Correct |
18 ms |
12484 KB |
Output is correct |
5 |
Correct |
13 ms |
12488 KB |
Output is correct |
6 |
Correct |
10 ms |
12484 KB |
Output is correct |
7 |
Correct |
19 ms |
12408 KB |
Output is correct |
8 |
Correct |
14 ms |
12460 KB |
Output is correct |
9 |
Correct |
12 ms |
12484 KB |
Output is correct |
10 |
Correct |
14 ms |
12456 KB |
Output is correct |
11 |
Correct |
12 ms |
12476 KB |
Output is correct |
12 |
Correct |
18 ms |
12368 KB |
Output is correct |
13 |
Correct |
14 ms |
12368 KB |
Output is correct |
14 |
Correct |
19 ms |
12368 KB |
Output is correct |
15 |
Correct |
26 ms |
12488 KB |
Output is correct |
16 |
Correct |
35 ms |
12368 KB |
Output is correct |
17 |
Correct |
39 ms |
12368 KB |
Output is correct |
18 |
Correct |
46 ms |
12384 KB |
Output is correct |
19 |
Correct |
35 ms |
12368 KB |
Output is correct |
20 |
Correct |
35 ms |
12368 KB |
Output is correct |
21 |
Correct |
47 ms |
12368 KB |
Output is correct |
22 |
Correct |
39 ms |
12368 KB |
Output is correct |
23 |
Correct |
16 ms |
12488 KB |
Output is correct |
24 |
Correct |
15 ms |
12488 KB |
Output is correct |
25 |
Correct |
42 ms |
12476 KB |
Output is correct |
26 |
Correct |
32 ms |
12480 KB |
Output is correct |
27 |
Correct |
13 ms |
12412 KB |
Output is correct |
28 |
Correct |
26 ms |
12496 KB |
Output is correct |
29 |
Correct |
32 ms |
12492 KB |
Output is correct |
30 |
Correct |
43 ms |
12480 KB |
Output is correct |
31 |
Correct |
37 ms |
12368 KB |
Output is correct |
32 |
Correct |
18 ms |
12440 KB |
Output is correct |
33 |
Correct |
10 ms |
12368 KB |
Output is correct |
34 |
Correct |
27 ms |
12496 KB |
Output is correct |
35 |
Correct |
13 ms |
12496 KB |
Output is correct |
36 |
Correct |
40 ms |
12624 KB |
Output is correct |
37 |
Correct |
12 ms |
12508 KB |
Output is correct |
38 |
Correct |
14 ms |
12476 KB |
Output is correct |
39 |
Correct |
40 ms |
12492 KB |
Output is correct |
40 |
Correct |
43 ms |
12368 KB |
Output is correct |
41 |
Correct |
50 ms |
12432 KB |
Output is correct |
42 |
Correct |
50 ms |
12480 KB |
Output is correct |
43 |
Correct |
49 ms |
12368 KB |
Output is correct |
44 |
Correct |
46 ms |
12368 KB |
Output is correct |
45 |
Correct |
25 ms |
12488 KB |
Output is correct |
46 |
Correct |
51 ms |
12488 KB |
Output is correct |
47 |
Correct |
49 ms |
12368 KB |
Output is correct |
48 |
Correct |
46 ms |
12368 KB |
Output is correct |
49 |
Correct |
49 ms |
12488 KB |
Output is correct |
50 |
Correct |
30 ms |
12368 KB |
Output is correct |
51 |
Correct |
50 ms |
12480 KB |
Output is correct |
52 |
Correct |
37 ms |
12480 KB |
Output is correct |
53 |
Correct |
14 ms |
12368 KB |
Output is correct |
54 |
Correct |
25 ms |
12484 KB |
Output is correct |
55 |
Correct |
47 ms |
12368 KB |
Output is correct |
56 |
Correct |
40 ms |
12484 KB |
Output is correct |
57 |
Correct |
49 ms |
12480 KB |
Output is correct |
58 |
Correct |
39 ms |
12368 KB |
Output is correct |
59 |
Correct |
37 ms |
12516 KB |
Output is correct |
60 |
Correct |
49 ms |
12368 KB |
Output is correct |
61 |
Correct |
15 ms |
12368 KB |
Output is correct |
62 |
Correct |
20 ms |
12468 KB |
Output is correct |
63 |
Correct |
14 ms |
12368 KB |
Output is correct |
64 |
Correct |
15 ms |
12476 KB |
Output is correct |
65 |
Correct |
13 ms |
12516 KB |
Output is correct |
66 |
Correct |
14 ms |
12368 KB |
Output is correct |
67 |
Correct |
11 ms |
12480 KB |
Output is correct |
68 |
Correct |
13 ms |
12484 KB |
Output is correct |
69 |
Correct |
16 ms |
12368 KB |
Output is correct |
70 |
Correct |
10 ms |
12476 KB |
Output is correct |
71 |
Correct |
36 ms |
12368 KB |
Output is correct |
72 |
Correct |
14 ms |
12368 KB |
Output is correct |
73 |
Correct |
51 ms |
12452 KB |
Output is correct |
74 |
Correct |
32 ms |
12368 KB |
Output is correct |
75 |
Correct |
15 ms |
12368 KB |
Output is correct |
76 |
Correct |
42 ms |
12376 KB |
Output is correct |
77 |
Correct |
50 ms |
12368 KB |
Output is correct |
78 |
Correct |
14 ms |
12368 KB |
Output is correct |
79 |
Correct |
29 ms |
12368 KB |
Output is correct |
80 |
Correct |
47 ms |
12380 KB |
Output is correct |
81 |
Correct |
28 ms |
12372 KB |
Output is correct |
82 |
Correct |
51 ms |
12496 KB |
Output is correct |
83 |
Correct |
14 ms |
12452 KB |
Output is correct |
84 |
Correct |
40 ms |
12368 KB |
Output is correct |
85 |
Correct |
26 ms |
12396 KB |
Output is correct |
86 |
Correct |
34 ms |
12448 KB |
Output is correct |
87 |
Correct |
11 ms |
12368 KB |
Output is correct |
88 |
Correct |
14 ms |
12368 KB |
Output is correct |
89 |
Correct |
18 ms |
12356 KB |
Output is correct |
90 |
Correct |
14 ms |
12408 KB |
Output is correct |
91 |
Correct |
14 ms |
12368 KB |
Output is correct |
92 |
Correct |
14 ms |
12472 KB |
Output is correct |
93 |
Correct |
18 ms |
12372 KB |
Output is correct |
94 |
Correct |
15 ms |
12456 KB |
Output is correct |
95 |
Correct |
20 ms |
12408 KB |
Output is correct |
96 |
Correct |
15 ms |
12368 KB |
Output is correct |
97 |
Correct |
29 ms |
12376 KB |
Output is correct |