Submission #745156

# Submission time Handle Problem Language Result Execution time Memory
745156 2023-05-19T13:17:23 Z CyberCraze Game (APIO22_game) C++17
100 / 100
2383 ms 63556 KB
#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 10 ms 14400 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14408 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 10 ms 14400 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14408 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 10 ms 14368 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 7 ms 14416 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 7 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 10 ms 14400 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14408 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 10 ms 14368 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 7 ms 14416 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 7 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 8 ms 14436 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14500 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 9 ms 14484 KB Output is correct
25 Correct 10 ms 14544 KB Output is correct
26 Correct 12 ms 14520 KB Output is correct
27 Correct 11 ms 14532 KB Output is correct
28 Correct 9 ms 14452 KB Output is correct
29 Correct 11 ms 14492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 10 ms 14400 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14408 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 10 ms 14368 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 7 ms 14416 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 7 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 8 ms 14436 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14500 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 9 ms 14484 KB Output is correct
25 Correct 10 ms 14544 KB Output is correct
26 Correct 12 ms 14520 KB Output is correct
27 Correct 11 ms 14532 KB Output is correct
28 Correct 9 ms 14452 KB Output is correct
29 Correct 11 ms 14492 KB Output is correct
30 Correct 26 ms 15944 KB Output is correct
31 Correct 13 ms 15148 KB Output is correct
32 Correct 31 ms 18000 KB Output is correct
33 Correct 29 ms 16564 KB Output is correct
34 Correct 58 ms 19616 KB Output is correct
35 Correct 65 ms 17924 KB Output is correct
36 Correct 64 ms 16712 KB Output is correct
37 Correct 57 ms 16936 KB Output is correct
38 Correct 44 ms 16612 KB Output is correct
39 Correct 51 ms 16648 KB Output is correct
40 Correct 76 ms 19528 KB Output is correct
41 Correct 69 ms 17340 KB Output is correct
42 Correct 59 ms 17096 KB Output is correct
43 Correct 71 ms 18216 KB Output is correct
44 Correct 86 ms 18200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14288 KB Output is correct
2 Correct 10 ms 14400 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14408 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 10 ms 14368 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 7 ms 14416 KB Output is correct
17 Correct 8 ms 14432 KB Output is correct
18 Correct 7 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 8 ms 14436 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14500 KB Output is correct
23 Correct 8 ms 14416 KB Output is correct
24 Correct 9 ms 14484 KB Output is correct
25 Correct 10 ms 14544 KB Output is correct
26 Correct 12 ms 14520 KB Output is correct
27 Correct 11 ms 14532 KB Output is correct
28 Correct 9 ms 14452 KB Output is correct
29 Correct 11 ms 14492 KB Output is correct
30 Correct 26 ms 15944 KB Output is correct
31 Correct 13 ms 15148 KB Output is correct
32 Correct 31 ms 18000 KB Output is correct
33 Correct 29 ms 16564 KB Output is correct
34 Correct 58 ms 19616 KB Output is correct
35 Correct 65 ms 17924 KB Output is correct
36 Correct 64 ms 16712 KB Output is correct
37 Correct 57 ms 16936 KB Output is correct
38 Correct 44 ms 16612 KB Output is correct
39 Correct 51 ms 16648 KB Output is correct
40 Correct 76 ms 19528 KB Output is correct
41 Correct 69 ms 17340 KB Output is correct
42 Correct 59 ms 17096 KB Output is correct
43 Correct 71 ms 18216 KB Output is correct
44 Correct 86 ms 18200 KB Output is correct
45 Correct 294 ms 29296 KB Output is correct
46 Correct 16 ms 16208 KB Output is correct
47 Correct 15 ms 16232 KB Output is correct
48 Correct 422 ms 50152 KB Output is correct
49 Correct 329 ms 37288 KB Output is correct
50 Correct 1176 ms 54264 KB Output is correct
51 Correct 1382 ms 50796 KB Output is correct
52 Correct 748 ms 37304 KB Output is correct
53 Correct 1072 ms 39788 KB Output is correct
54 Correct 1243 ms 41760 KB Output is correct
55 Correct 1613 ms 42852 KB Output is correct
56 Correct 2083 ms 44828 KB Output is correct
57 Correct 717 ms 38672 KB Output is correct
58 Correct 755 ms 38492 KB Output is correct
59 Correct 729 ms 38588 KB Output is correct
60 Correct 824 ms 39000 KB Output is correct
61 Correct 1041 ms 39760 KB Output is correct
62 Correct 780 ms 45776 KB Output is correct
63 Correct 668 ms 42208 KB Output is correct
64 Correct 1751 ms 63556 KB Output is correct
65 Correct 756 ms 42996 KB Output is correct
66 Correct 636 ms 39008 KB Output is correct
67 Correct 1239 ms 47884 KB Output is correct
68 Correct 268 ms 33480 KB Output is correct
69 Correct 75 ms 27592 KB Output is correct
70 Correct 1286 ms 46808 KB Output is correct
71 Correct 407 ms 36168 KB Output is correct
72 Correct 305 ms 31832 KB Output is correct
73 Correct 903 ms 44184 KB Output is correct
74 Correct 2383 ms 45228 KB Output is correct
75 Correct 1502 ms 54496 KB Output is correct
76 Correct 1833 ms 54708 KB Output is correct