#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(42069);
const int CHECK=447;
ii memo[200005];
ii get(int i){
if (memo[i]!=ii(-1,-1)) return memo[i];
auto temp=ask(i);
return memo[i]=ii(temp[0],temp[1]);
}
int mx;
vector<int> good;
void dnc(int l,int r,int i,int j){
//rep(x,0,100000000) ;
//cout<<l<<" "<<r<<" "<<i<<" "<<j<<endl;
if (r<l) return;
if (i==j) return;
int m=l+r>>1;
int m2=m;
while (m2<=r && get(m2).fi+get(m2).se!=mx){
good.push_back(m2);
m2++;
}
if (m2>r) dnc(l,m-1,i,j-(m2-m));
else{
auto temp=get(m2);
dnc(l,m-1,i,temp.fi-(m2-m));
dnc(m2+1,r,temp.fi,j);
}
}
int find_best(int n) {
memset(memo,-1,sizeof(memo));
vector<int> pos;
rep(x,0,n) pos.push_back(x);
rep(x,0,n) swap(pos[x],pos[rng()%(x+1)]);
rep(x,0,min(n,CHECK)){
auto temp=get(pos[x]);
mx=max(mx,temp.fi+temp.se);
}
dnc(0,n-1,0,mx);
//for (auto &it:good) cout<<it<<" "; cout<<endl;
for (auto &it:good){
if (get(it)==ii(0,0)) return it;
}
return -1;
}
Compilation message
prize.cpp: In function 'void dnc(int, int, int, int)':
prize.cpp:37:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int m=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3064 KB |
Output is correct |
2 |
Correct |
11 ms |
3064 KB |
Output is correct |
3 |
Correct |
12 ms |
3064 KB |
Output is correct |
4 |
Correct |
13 ms |
3064 KB |
Output is correct |
5 |
Correct |
13 ms |
3064 KB |
Output is correct |
6 |
Correct |
13 ms |
3192 KB |
Output is correct |
7 |
Correct |
11 ms |
3064 KB |
Output is correct |
8 |
Correct |
12 ms |
3064 KB |
Output is correct |
9 |
Correct |
12 ms |
3064 KB |
Output is correct |
10 |
Correct |
12 ms |
3064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3064 KB |
Output is correct |
2 |
Correct |
13 ms |
3064 KB |
Output is correct |
3 |
Correct |
12 ms |
3064 KB |
Output is correct |
4 |
Correct |
12 ms |
3064 KB |
Output is correct |
5 |
Correct |
11 ms |
3192 KB |
Output is correct |
6 |
Correct |
12 ms |
3064 KB |
Output is correct |
7 |
Correct |
12 ms |
3064 KB |
Output is correct |
8 |
Correct |
13 ms |
3064 KB |
Output is correct |
9 |
Correct |
12 ms |
3192 KB |
Output is correct |
10 |
Correct |
12 ms |
3064 KB |
Output is correct |
11 |
Correct |
13 ms |
3064 KB |
Output is correct |
12 |
Correct |
15 ms |
3064 KB |
Output is correct |
13 |
Correct |
14 ms |
3064 KB |
Output is correct |
14 |
Correct |
16 ms |
2048 KB |
Output is correct |
15 |
Correct |
53 ms |
3064 KB |
Output is correct |
16 |
Correct |
42 ms |
3064 KB |
Output is correct |
17 |
Correct |
47 ms |
3064 KB |
Output is correct |
18 |
Correct |
45 ms |
3064 KB |
Output is correct |
19 |
Correct |
38 ms |
3064 KB |
Output is correct |
20 |
Correct |
31 ms |
2556 KB |
Output is correct |
21 |
Correct |
52 ms |
3064 KB |
Output is correct |
22 |
Correct |
44 ms |
3064 KB |
Output is correct |
23 |
Correct |
14 ms |
3064 KB |
Output is correct |
24 |
Correct |
16 ms |
3064 KB |
Output is correct |
25 |
Correct |
51 ms |
3064 KB |
Output is correct |
26 |
Correct |
47 ms |
3064 KB |
Output is correct |
27 |
Correct |
13 ms |
3064 KB |
Output is correct |
28 |
Correct |
40 ms |
3064 KB |
Output is correct |
29 |
Correct |
45 ms |
3064 KB |
Output is correct |
30 |
Correct |
59 ms |
3064 KB |
Output is correct |
31 |
Correct |
47 ms |
3064 KB |
Output is correct |
32 |
Correct |
17 ms |
3064 KB |
Output is correct |
33 |
Correct |
2 ms |
1920 KB |
Output is correct |
34 |
Correct |
45 ms |
3064 KB |
Output is correct |
35 |
Correct |
14 ms |
3064 KB |
Output is correct |
36 |
Correct |
52 ms |
3064 KB |
Output is correct |
37 |
Correct |
13 ms |
3064 KB |
Output is correct |
38 |
Correct |
10 ms |
3064 KB |
Output is correct |
39 |
Correct |
54 ms |
3064 KB |
Output is correct |
40 |
Correct |
49 ms |
3064 KB |
Output is correct |
41 |
Correct |
47 ms |
3064 KB |
Output is correct |
42 |
Correct |
47 ms |
3064 KB |
Output is correct |
43 |
Correct |
49 ms |
3064 KB |
Output is correct |
44 |
Correct |
58 ms |
3064 KB |
Output is correct |
45 |
Correct |
44 ms |
3192 KB |
Output is correct |
46 |
Correct |
43 ms |
3192 KB |
Output is correct |
47 |
Correct |
50 ms |
3064 KB |
Output is correct |
48 |
Correct |
45 ms |
3064 KB |
Output is correct |
49 |
Correct |
55 ms |
3064 KB |
Output is correct |
50 |
Correct |
59 ms |
3064 KB |
Output is correct |
51 |
Correct |
51 ms |
3064 KB |
Output is correct |
52 |
Correct |
50 ms |
3064 KB |
Output is correct |
53 |
Correct |
13 ms |
3064 KB |
Output is correct |
54 |
Correct |
51 ms |
3064 KB |
Output is correct |
55 |
Correct |
32 ms |
3064 KB |
Output is correct |
56 |
Correct |
32 ms |
3064 KB |
Output is correct |
57 |
Correct |
43 ms |
3064 KB |
Output is correct |
58 |
Correct |
55 ms |
3064 KB |
Output is correct |
59 |
Correct |
50 ms |
3064 KB |
Output is correct |
60 |
Correct |
57 ms |
3064 KB |
Output is correct |
61 |
Correct |
12 ms |
3192 KB |
Output is correct |
62 |
Correct |
13 ms |
3064 KB |
Output is correct |
63 |
Correct |
12 ms |
3064 KB |
Output is correct |
64 |
Correct |
13 ms |
3064 KB |
Output is correct |
65 |
Correct |
12 ms |
3064 KB |
Output is correct |
66 |
Correct |
12 ms |
3096 KB |
Output is correct |
67 |
Correct |
14 ms |
3064 KB |
Output is correct |
68 |
Correct |
15 ms |
3064 KB |
Output is correct |
69 |
Correct |
16 ms |
3064 KB |
Output is correct |
70 |
Correct |
14 ms |
3064 KB |
Output is correct |
71 |
Partially correct |
36 ms |
3064 KB |
Partially correct - number of queries: 5188 |
72 |
Correct |
15 ms |
3064 KB |
Output is correct |
73 |
Partially correct |
50 ms |
3064 KB |
Partially correct - number of queries: 5127 |
74 |
Partially correct |
55 ms |
3064 KB |
Partially correct - number of queries: 5154 |
75 |
Correct |
13 ms |
3064 KB |
Output is correct |
76 |
Correct |
49 ms |
3064 KB |
Output is correct |
77 |
Correct |
58 ms |
3064 KB |
Output is correct |
78 |
Correct |
16 ms |
3064 KB |
Output is correct |
79 |
Correct |
35 ms |
3064 KB |
Output is correct |
80 |
Correct |
54 ms |
3064 KB |
Output is correct |
81 |
Correct |
53 ms |
3064 KB |
Output is correct |
82 |
Correct |
36 ms |
3064 KB |
Output is correct |
83 |
Correct |
12 ms |
3064 KB |
Output is correct |
84 |
Correct |
47 ms |
3064 KB |
Output is correct |
85 |
Correct |
55 ms |
3064 KB |
Output is correct |
86 |
Correct |
40 ms |
3064 KB |
Output is correct |
87 |
Correct |
15 ms |
3064 KB |
Output is correct |
88 |
Correct |
38 ms |
3064 KB |
Output is correct |
89 |
Correct |
48 ms |
3064 KB |
Output is correct |
90 |
Correct |
12 ms |
3064 KB |
Output is correct |
91 |
Correct |
32 ms |
3064 KB |
Output is correct |
92 |
Correct |
38 ms |
3064 KB |
Output is correct |
93 |
Correct |
46 ms |
3064 KB |
Output is correct |
94 |
Correct |
43 ms |
3064 KB |
Output is correct |
95 |
Correct |
42 ms |
3064 KB |
Output is correct |
96 |
Correct |
42 ms |
3064 KB |
Output is correct |
97 |
Correct |
44 ms |
3064 KB |
Output is correct |