Submission #754039

# Submission time Handle Problem Language Result Execution time Memory
754039 2023-06-06T13:46:10 Z Joibangla Game (APIO22_game) C++17
100 / 100
2549 ms 63348 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 7 ms 14288 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14372 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14372 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14348 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14348 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 9 ms 14308 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 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 8 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14372 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14348 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14348 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 9 ms 14308 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 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 8 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14452 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 9 ms 14496 KB Output is correct
29 Correct 12 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14372 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14348 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14348 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 9 ms 14308 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 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 8 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14452 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 9 ms 14496 KB Output is correct
29 Correct 12 ms 14532 KB Output is correct
30 Correct 39 ms 15932 KB Output is correct
31 Correct 13 ms 15124 KB Output is correct
32 Correct 35 ms 18088 KB Output is correct
33 Correct 33 ms 16620 KB Output is correct
34 Correct 65 ms 19572 KB Output is correct
35 Correct 84 ms 17928 KB Output is correct
36 Correct 71 ms 16760 KB Output is correct
37 Correct 58 ms 16932 KB Output is correct
38 Correct 57 ms 16616 KB Output is correct
39 Correct 65 ms 16744 KB Output is correct
40 Correct 107 ms 19428 KB Output is correct
41 Correct 70 ms 17420 KB Output is correct
42 Correct 52 ms 17096 KB Output is correct
43 Correct 85 ms 18280 KB Output is correct
44 Correct 104 ms 18072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14372 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14348 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14348 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 9 ms 14308 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 7 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 8 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 8 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14452 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 9 ms 14496 KB Output is correct
29 Correct 12 ms 14532 KB Output is correct
30 Correct 39 ms 15932 KB Output is correct
31 Correct 13 ms 15124 KB Output is correct
32 Correct 35 ms 18088 KB Output is correct
33 Correct 33 ms 16620 KB Output is correct
34 Correct 65 ms 19572 KB Output is correct
35 Correct 84 ms 17928 KB Output is correct
36 Correct 71 ms 16760 KB Output is correct
37 Correct 58 ms 16932 KB Output is correct
38 Correct 57 ms 16616 KB Output is correct
39 Correct 65 ms 16744 KB Output is correct
40 Correct 107 ms 19428 KB Output is correct
41 Correct 70 ms 17420 KB Output is correct
42 Correct 52 ms 17096 KB Output is correct
43 Correct 85 ms 18280 KB Output is correct
44 Correct 104 ms 18072 KB Output is correct
45 Correct 292 ms 29232 KB Output is correct
46 Correct 18 ms 16164 KB Output is correct
47 Correct 16 ms 16368 KB Output is correct
48 Correct 424 ms 50004 KB Output is correct
49 Correct 316 ms 37312 KB Output is correct
50 Correct 1247 ms 54188 KB Output is correct
51 Correct 1311 ms 50872 KB Output is correct
52 Correct 655 ms 37260 KB Output is correct
53 Correct 1047 ms 39764 KB Output is correct
54 Correct 1266 ms 41732 KB Output is correct
55 Correct 1643 ms 42968 KB Output is correct
56 Correct 2146 ms 44676 KB Output is correct
57 Correct 820 ms 38468 KB Output is correct
58 Correct 832 ms 38568 KB Output is correct
59 Correct 739 ms 38640 KB Output is correct
60 Correct 878 ms 38928 KB Output is correct
61 Correct 1095 ms 39724 KB Output is correct
62 Correct 811 ms 45804 KB Output is correct
63 Correct 652 ms 42208 KB Output is correct
64 Correct 1801 ms 63348 KB Output is correct
65 Correct 778 ms 43172 KB Output is correct
66 Correct 622 ms 38900 KB Output is correct
67 Correct 1178 ms 47988 KB Output is correct
68 Correct 270 ms 33504 KB Output is correct
69 Correct 87 ms 27380 KB Output is correct
70 Correct 1272 ms 46660 KB Output is correct
71 Correct 380 ms 36188 KB Output is correct
72 Correct 293 ms 31836 KB Output is correct
73 Correct 947 ms 44396 KB Output is correct
74 Correct 2549 ms 45100 KB Output is correct
75 Correct 1659 ms 54416 KB Output is correct
76 Correct 1907 ms 54728 KB Output is correct