#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int 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(chrono::system_clock::now().time_since_epoch().count());
int num[50005];
int best[50005];
int CURR=0;
bool same(int x){
int temp=Query(x);
int res=CURR==temp;
CURR=temp;
return res;
}
int n;
void solve(vector<int> l,vector<int> r,bool in){
int n=sz(l);
if (n==0) return;
if (n==1){
Answer(l[0],r[0]);
}
else{
vector<int> l1,l2;
vector<int> r1,r2;
rep(x,0,best[n]) l1.pub(l[x]);
rep(x,best[n],n) l2.pub(l[x]);
for (auto it:l1) same(it);
for (auto it:r){
if (sz(l1)==sz(r1)) r2.pub(it);
else if (sz(l2)==sz(r2)) r1.pub(it);
else if (same(it) != in) r1.pub(it);
else r2.pub(it);
}
solve(l1,r1,!in);
solve(l2,r2,in);
}
}
vector<int> get(vector<int> v){
vector<int> l,r;
rep(x,0,sz(v)){
if (same(v[x])) r.pub(v[x]);
else l.pub(v[x]);
}
vector<int> good,bad;
for (auto it:l){
if (same(it)) good.pub(it);
else bad.pub(it);
}
solve(good,r,false);
return bad;
}
void Solve(signed N) {
num[1]=0;
rep(x,2,50005){
num[x]=1e9;
int l=max(1LL,(int)(x*0.25)),r=min(x,(int)(x*0.4)+2);
rep(y,l,r) if (num[x]>num[y]+num[x-y]+x+y){
num[x]=num[y]+num[x-y]+x+y;
best[x]=y;
}
}
n=N;
vector<int> idx;
rep(x,1,2*n+1) idx.pub(x);
shuffle(all(idx),rng);
vector<int> l,r;
rep(x,0,n) l.pub(idx[x]);
rep(x,n,2*n) r.pub(idx[x]);
solve(get(l),get(r),false);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
1104 KB |
Output is correct |
2 |
Correct |
263 ms |
1388 KB |
Output is correct |
3 |
Correct |
269 ms |
1560 KB |
Output is correct |
4 |
Correct |
269 ms |
2056 KB |
Output is correct |
5 |
Correct |
278 ms |
3084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
19 |
Correct |
317 ms |
6356 KB |
Output is correct |
20 |
Correct |
329 ms |
6308 KB |
Output is correct |
21 |
Correct |
378 ms |
6320 KB |
Output is correct |
22 |
Correct |
347 ms |
6260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
19 |
Correct |
317 ms |
6356 KB |
Output is correct |
20 |
Correct |
329 ms |
6308 KB |
Output is correct |
21 |
Correct |
378 ms |
6320 KB |
Output is correct |
22 |
Correct |
347 ms |
6260 KB |
Output is correct |
23 |
Correct |
326 ms |
6456 KB |
Output is correct |
24 |
Correct |
321 ms |
6460 KB |
Output is correct |
25 |
Correct |
349 ms |
6480 KB |
Output is correct |
26 |
Correct |
318 ms |
6328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
19 |
Correct |
317 ms |
6356 KB |
Output is correct |
20 |
Correct |
329 ms |
6308 KB |
Output is correct |
21 |
Correct |
378 ms |
6320 KB |
Output is correct |
22 |
Correct |
347 ms |
6260 KB |
Output is correct |
23 |
Correct |
326 ms |
6456 KB |
Output is correct |
24 |
Correct |
321 ms |
6460 KB |
Output is correct |
25 |
Correct |
349 ms |
6480 KB |
Output is correct |
26 |
Correct |
318 ms |
6328 KB |
Output is correct |
27 |
Correct |
326 ms |
6572 KB |
Output is correct |
28 |
Correct |
340 ms |
6640 KB |
Output is correct |
29 |
Correct |
307 ms |
6568 KB |
Output is correct |
30 |
Correct |
321 ms |
6324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
19 |
Correct |
317 ms |
6356 KB |
Output is correct |
20 |
Correct |
329 ms |
6308 KB |
Output is correct |
21 |
Correct |
378 ms |
6320 KB |
Output is correct |
22 |
Correct |
347 ms |
6260 KB |
Output is correct |
23 |
Correct |
326 ms |
6456 KB |
Output is correct |
24 |
Correct |
321 ms |
6460 KB |
Output is correct |
25 |
Correct |
349 ms |
6480 KB |
Output is correct |
26 |
Correct |
318 ms |
6328 KB |
Output is correct |
27 |
Correct |
326 ms |
6572 KB |
Output is correct |
28 |
Correct |
340 ms |
6640 KB |
Output is correct |
29 |
Correct |
307 ms |
6568 KB |
Output is correct |
30 |
Correct |
321 ms |
6324 KB |
Output is correct |
31 |
Correct |
338 ms |
6652 KB |
Output is correct |
32 |
Correct |
307 ms |
6748 KB |
Output is correct |
33 |
Correct |
316 ms |
6688 KB |
Output is correct |
34 |
Correct |
376 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
1060 KB |
Output is correct |
2 |
Correct |
269 ms |
968 KB |
Output is correct |
3 |
Correct |
262 ms |
1092 KB |
Output is correct |
4 |
Correct |
267 ms |
1096 KB |
Output is correct |
5 |
Correct |
286 ms |
1104 KB |
Output is correct |
6 |
Correct |
263 ms |
1388 KB |
Output is correct |
7 |
Correct |
269 ms |
1560 KB |
Output is correct |
8 |
Correct |
269 ms |
2056 KB |
Output is correct |
9 |
Correct |
278 ms |
3084 KB |
Output is correct |
10 |
Correct |
262 ms |
1184 KB |
Output is correct |
11 |
Correct |
299 ms |
2408 KB |
Output is correct |
12 |
Correct |
291 ms |
3108 KB |
Output is correct |
13 |
Correct |
295 ms |
3048 KB |
Output is correct |
14 |
Correct |
291 ms |
2988 KB |
Output is correct |
15 |
Correct |
442 ms |
6096 KB |
Output is correct |
16 |
Correct |
316 ms |
6052 KB |
Output is correct |
17 |
Correct |
321 ms |
6108 KB |
Output is correct |
18 |
Correct |
341 ms |
5876 KB |
Output is correct |
19 |
Correct |
317 ms |
6356 KB |
Output is correct |
20 |
Correct |
329 ms |
6308 KB |
Output is correct |
21 |
Correct |
378 ms |
6320 KB |
Output is correct |
22 |
Correct |
347 ms |
6260 KB |
Output is correct |
23 |
Correct |
326 ms |
6456 KB |
Output is correct |
24 |
Correct |
321 ms |
6460 KB |
Output is correct |
25 |
Correct |
349 ms |
6480 KB |
Output is correct |
26 |
Correct |
318 ms |
6328 KB |
Output is correct |
27 |
Correct |
326 ms |
6572 KB |
Output is correct |
28 |
Correct |
340 ms |
6640 KB |
Output is correct |
29 |
Correct |
307 ms |
6568 KB |
Output is correct |
30 |
Correct |
321 ms |
6324 KB |
Output is correct |
31 |
Correct |
338 ms |
6652 KB |
Output is correct |
32 |
Correct |
307 ms |
6748 KB |
Output is correct |
33 |
Correct |
316 ms |
6688 KB |
Output is correct |
34 |
Correct |
376 ms |
6492 KB |
Output is correct |
35 |
Correct |
330 ms |
6764 KB |
Output is correct |
36 |
Correct |
328 ms |
6736 KB |
Output is correct |
37 |
Correct |
343 ms |
6888 KB |
Output is correct |
38 |
Correct |
313 ms |
6552 KB |
Output is correct |