# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572469 |
2022-06-04T13:04:47 Z |
model_code |
Game (APIO22_game) |
C++17 |
|
2570 ms |
63480 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
using vi=vector<int>;
#define PB push_back
const int Nmax=300010;
const int Lmax=20;
vi g[Nmax][2];
int n,k,maxL;
int pos[Nmax];
bool reach[Lmax][Nmax][2];
int Level(int x){
return 31-__builtin_clz(x);
}
int Par(int x,int lv){
int w=Level(x);
if(w<lv)return -1;
else return x>>(w-lv);
}
bool SameNode(int lv,int u,int v){
int up=Par(pos[u],lv),vp=Par(pos[v],lv);
return up!=-1&&up==vp;
}
void init(int N, int K) {
n=N+2;
k=K+2;
maxL=0;
while((1<<maxL)<k)maxL++;
REP(i,k){
pos[i]=(1<<maxL)+i;
int x=i;
for(int j=maxL-1;j>=0;j--){
reach[j][i][(x&1)^1]=true;
x>>=1;
}
}
FOR(i,k,n)
pos[i]=1;
}
bool dfs(int lv,int v,int t,vi& vs);
bool enter(int lv,int u,int v,int t,vi& vs){
if(v<k)return false;
if(SameNode(lv,u,v)&&reach[lv][u][t]&&!reach[lv][v][t])
return dfs(lv,v,t,vs);
return false;
}
bool dfs(int lv,int v,int t,vi& vs){
assert(!reach[lv][v][t]);
reach[lv][v][t]=true;
if(reach[lv][v][t^1])return true;
vs.PB(v);
pos[v]=pos[v]*2+(t^1);
for(auto to:g[v][t])
if(enter(lv,v,to,t,vs))return true;
return false;
}
int add_teleporter(int u, int v){
if(u<k-2)u++;
else u+=2;
if(v<k-2)v++;
else v+=2;
if(max(u,v)<k){
if(u<v)return 0;
else return 1;
}
g[u][0].PB(v);
g[v][1].PB(u);
vi vs;
REP(lv,maxL){
vi nx;
if(enter(lv,u,v,0,nx))return 1;
if(enter(lv,v,u,1,nx))return 1;
for(auto v:vs)
REP(t,2)
for(auto from:g[v][t^1])
if(enter(lv,from,v,t,nx))return 1;
vs.swap(nx);
}
if(!vs.empty())return 1;
else return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
9 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14340 KB |
Output is correct |
7 |
Correct |
10 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
9 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14340 KB |
Output is correct |
7 |
Correct |
10 ms |
14416 KB |
Output is correct |
8 |
Correct |
9 ms |
14412 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
14360 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
9 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14340 KB |
Output is correct |
7 |
Correct |
10 ms |
14416 KB |
Output is correct |
8 |
Correct |
9 ms |
14412 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
14360 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14452 KB |
Output is correct |
22 |
Correct |
9 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14436 KB |
Output is correct |
24 |
Correct |
9 ms |
14544 KB |
Output is correct |
25 |
Correct |
11 ms |
14532 KB |
Output is correct |
26 |
Correct |
12 ms |
14544 KB |
Output is correct |
27 |
Correct |
11 ms |
14484 KB |
Output is correct |
28 |
Correct |
10 ms |
14512 KB |
Output is correct |
29 |
Correct |
11 ms |
14480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
9 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14340 KB |
Output is correct |
7 |
Correct |
10 ms |
14416 KB |
Output is correct |
8 |
Correct |
9 ms |
14412 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
14360 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14452 KB |
Output is correct |
22 |
Correct |
9 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14436 KB |
Output is correct |
24 |
Correct |
9 ms |
14544 KB |
Output is correct |
25 |
Correct |
11 ms |
14532 KB |
Output is correct |
26 |
Correct |
12 ms |
14544 KB |
Output is correct |
27 |
Correct |
11 ms |
14484 KB |
Output is correct |
28 |
Correct |
10 ms |
14512 KB |
Output is correct |
29 |
Correct |
11 ms |
14480 KB |
Output is correct |
30 |
Correct |
28 ms |
15996 KB |
Output is correct |
31 |
Correct |
17 ms |
15184 KB |
Output is correct |
32 |
Correct |
37 ms |
17992 KB |
Output is correct |
33 |
Correct |
30 ms |
16584 KB |
Output is correct |
34 |
Correct |
70 ms |
19584 KB |
Output is correct |
35 |
Correct |
94 ms |
17940 KB |
Output is correct |
36 |
Correct |
71 ms |
16768 KB |
Output is correct |
37 |
Correct |
63 ms |
16904 KB |
Output is correct |
38 |
Correct |
65 ms |
16596 KB |
Output is correct |
39 |
Correct |
58 ms |
16736 KB |
Output is correct |
40 |
Correct |
72 ms |
19412 KB |
Output is correct |
41 |
Correct |
62 ms |
17344 KB |
Output is correct |
42 |
Correct |
58 ms |
17072 KB |
Output is correct |
43 |
Correct |
84 ms |
18152 KB |
Output is correct |
44 |
Correct |
89 ms |
18084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
9 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14340 KB |
Output is correct |
7 |
Correct |
10 ms |
14416 KB |
Output is correct |
8 |
Correct |
9 ms |
14412 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
10 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
11 ms |
14360 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14452 KB |
Output is correct |
22 |
Correct |
9 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14436 KB |
Output is correct |
24 |
Correct |
9 ms |
14544 KB |
Output is correct |
25 |
Correct |
11 ms |
14532 KB |
Output is correct |
26 |
Correct |
12 ms |
14544 KB |
Output is correct |
27 |
Correct |
11 ms |
14484 KB |
Output is correct |
28 |
Correct |
10 ms |
14512 KB |
Output is correct |
29 |
Correct |
11 ms |
14480 KB |
Output is correct |
30 |
Correct |
28 ms |
15996 KB |
Output is correct |
31 |
Correct |
17 ms |
15184 KB |
Output is correct |
32 |
Correct |
37 ms |
17992 KB |
Output is correct |
33 |
Correct |
30 ms |
16584 KB |
Output is correct |
34 |
Correct |
70 ms |
19584 KB |
Output is correct |
35 |
Correct |
94 ms |
17940 KB |
Output is correct |
36 |
Correct |
71 ms |
16768 KB |
Output is correct |
37 |
Correct |
63 ms |
16904 KB |
Output is correct |
38 |
Correct |
65 ms |
16596 KB |
Output is correct |
39 |
Correct |
58 ms |
16736 KB |
Output is correct |
40 |
Correct |
72 ms |
19412 KB |
Output is correct |
41 |
Correct |
62 ms |
17344 KB |
Output is correct |
42 |
Correct |
58 ms |
17072 KB |
Output is correct |
43 |
Correct |
84 ms |
18152 KB |
Output is correct |
44 |
Correct |
89 ms |
18084 KB |
Output is correct |
45 |
Correct |
297 ms |
29208 KB |
Output is correct |
46 |
Correct |
20 ms |
16208 KB |
Output is correct |
47 |
Correct |
14 ms |
16208 KB |
Output is correct |
48 |
Correct |
421 ms |
49960 KB |
Output is correct |
49 |
Correct |
321 ms |
37276 KB |
Output is correct |
50 |
Correct |
1338 ms |
54164 KB |
Output is correct |
51 |
Correct |
1302 ms |
50788 KB |
Output is correct |
52 |
Correct |
684 ms |
37240 KB |
Output is correct |
53 |
Correct |
998 ms |
39768 KB |
Output is correct |
54 |
Correct |
1323 ms |
41768 KB |
Output is correct |
55 |
Correct |
1775 ms |
42928 KB |
Output is correct |
56 |
Correct |
2277 ms |
44724 KB |
Output is correct |
57 |
Correct |
735 ms |
38460 KB |
Output is correct |
58 |
Correct |
746 ms |
38640 KB |
Output is correct |
59 |
Correct |
793 ms |
38656 KB |
Output is correct |
60 |
Correct |
952 ms |
38976 KB |
Output is correct |
61 |
Correct |
1085 ms |
39724 KB |
Output is correct |
62 |
Correct |
819 ms |
45792 KB |
Output is correct |
63 |
Correct |
655 ms |
42220 KB |
Output is correct |
64 |
Correct |
1852 ms |
63480 KB |
Output is correct |
65 |
Correct |
847 ms |
43048 KB |
Output is correct |
66 |
Correct |
653 ms |
38880 KB |
Output is correct |
67 |
Correct |
1318 ms |
48124 KB |
Output is correct |
68 |
Correct |
263 ms |
33488 KB |
Output is correct |
69 |
Correct |
78 ms |
27408 KB |
Output is correct |
70 |
Correct |
1293 ms |
46728 KB |
Output is correct |
71 |
Correct |
362 ms |
36052 KB |
Output is correct |
72 |
Correct |
304 ms |
31788 KB |
Output is correct |
73 |
Correct |
974 ms |
44272 KB |
Output is correct |
74 |
Correct |
2570 ms |
45128 KB |
Output is correct |
75 |
Correct |
1736 ms |
54428 KB |
Output is correct |
76 |
Correct |
1947 ms |
54660 KB |
Output is correct |