답안 #817034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817034 2023-08-09T08:44:04 Z 이종영(#10379) 게임 (APIO22_game) C++17
100 / 100
1777 ms 117308 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N=3e5+5,H=20;
int n,k;
int d[N],p[N],lc[N],rc[N];
int in[N][H][2];
vector<int> g[N],gr[N];
int build(int h,int l,int r){
	if(l>r) return 0;
	int m=(l+r)>>1;
	d[m]=h;
	for(int i=l;i<=m;i++) in[i][h][0]=m;
	for(int i=m;i<=r;i++) in[i][h][1]=m;
	for(int i=h+1;i<H;i++) in[m][i][0]=in[m][i][1]=-1;
	if(l==r) return m;
	lc[m]=build(h+1,l,m-1);
	if(lc[m]) p[lc[m]]=m;
	rc[m]=build(h+1,m+1,r);
	if(rc[m]) p[rc[m]]=m;
	return m;
}
void init(int n_, int k_){
	n=n_;
	k=k_;
	for(int i=1;i<k;i++){
		g[i].emplace_back(i+1);
		gr[i+1].emplace_back(i);
	}
	lc[0]=rc[0]=build(1,1,k);
}
vector<int> wait[N][2];
bool pos(int u,int m){
	if(m==lc[p[m]]) return in[u][d[p[m]]][0]==p[m];
	return in[u][d[p[m]]][1]==p[m];
}
bool dfsr(int u,int m){
	if(in[u][d[m]][0]) return 0;
	in[u][d[m]][0]=m;
	if(in[u][d[m]][1]){
		return 1;
	}
	if(lc[m]){
		for(int v: g[u]) if(in[v][d[m]+1][0]==lc[m]){
			wait[lc[m]][0].emplace_back(u);
			break;
		}
		for(int v: gr[u]) if(in[v][d[m]+1][1]==lc[m]){
			wait[lc[m]][1].emplace_back(u);
			break;
		}
	}
	for(int v: gr[u]) if(pos(v,m)){
		if(dfsr(v,m)) return 1;
	}
	return 0;
}
bool dfs(int u,int m){
	if(in[u][d[m]][1]) return 0;
	in[u][d[m]][1]=m;
	if(in[u][d[m]][0]){
		return 1;
	}
	if(rc[m]){
		for(int v: g[u]) if(in[v][d[m]+1][0]==rc[m]){
			wait[rc[m]][0].emplace_back(u);
			break;
		}
		for(int v: gr[u]) if(in[v][d[m]+1][1]==rc[m]){
			wait[rc[m]][1].emplace_back(u);
			break;
		}
	}
	for(int v: g[u]) if(pos(v,m)){
		if(dfs(v,m)) return 1;
	}
	return 0;
}
bool add(int m,int c){
	if(!wait[m][c].size()) return 0;
	if(!c){
		for(int u: wait[m][0]) if(dfsr(u,m)) return 1;
		if(add(lc[m],0)) return 1;
		if(add(lc[m],1)) return 1;
	} else{
		for(int u: wait[m][1]) if(dfs(u,m)) return 1;
		if(add(rc[m],0)) return 1;
		if(add(rc[m],1)) return 1;
	}
	wait[m][c].clear();
	return 0;
}
bool add1(int l,int r,int u,int v){
	if(l>r) return 0;
	int m=(l+r)>>1;
	if(in[v][d[m]][0]==m){
		if(u==m) return 1;
		if(!in[u][d[m]][0]){
			wait[m][0].emplace_back(u);
			return add(m,0);
		}
	}
	if(in[u][d[m]][0]==m&&in[v][d[m]][0]==m) return add1(l,m-1,u,v);
	if(in[u][d[m]][1]==m&&in[v][d[m]][1]==m) return add1(m+1,r,u,v);
	return 0;
}
bool add2(int l,int r,int u,int v){
	if(l>r) return 0;
	int m=(l+r)>>1;
	if(in[u][d[m]][1]==m){
		if(v==m) return 1;
		if(!in[v][d[m]][1]){
			wait[m][1].emplace_back(v);
			return add(m,1);
		}
	}
	if(in[u][d[m]][0]==m&&in[v][d[m]][0]==m) return add2(l,m-1,u,v);
	if(in[u][d[m]][1]==m&&in[v][d[m]][1]==m) return add2(m+1,r,u,v);
	return 0;
}
int add_teleporter(int u, int v){
	u++; v++;
	g[u].emplace_back(v);
	gr[v].emplace_back(u);
	if(add1(1,k,u,v)) return 1;
	if(add2(1,k,u,v)) return 1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28496 KB Output is correct
2 Correct 14 ms 28496 KB Output is correct
3 Correct 16 ms 28532 KB Output is correct
4 Correct 15 ms 28496 KB Output is correct
5 Correct 16 ms 28496 KB Output is correct
6 Correct 16 ms 28436 KB Output is correct
7 Correct 16 ms 28432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28496 KB Output is correct
2 Correct 14 ms 28496 KB Output is correct
3 Correct 16 ms 28532 KB Output is correct
4 Correct 15 ms 28496 KB Output is correct
5 Correct 16 ms 28496 KB Output is correct
6 Correct 16 ms 28436 KB Output is correct
7 Correct 16 ms 28432 KB Output is correct
8 Correct 18 ms 28508 KB Output is correct
9 Correct 17 ms 28504 KB Output is correct
10 Correct 16 ms 28436 KB Output is correct
11 Correct 17 ms 28496 KB Output is correct
12 Correct 16 ms 28496 KB Output is correct
13 Correct 15 ms 28496 KB Output is correct
14 Correct 17 ms 28532 KB Output is correct
15 Correct 18 ms 28516 KB Output is correct
16 Correct 15 ms 28496 KB Output is correct
17 Correct 16 ms 28532 KB Output is correct
18 Correct 16 ms 28508 KB Output is correct
19 Correct 17 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28496 KB Output is correct
2 Correct 14 ms 28496 KB Output is correct
3 Correct 16 ms 28532 KB Output is correct
4 Correct 15 ms 28496 KB Output is correct
5 Correct 16 ms 28496 KB Output is correct
6 Correct 16 ms 28436 KB Output is correct
7 Correct 16 ms 28432 KB Output is correct
8 Correct 18 ms 28508 KB Output is correct
9 Correct 17 ms 28504 KB Output is correct
10 Correct 16 ms 28436 KB Output is correct
11 Correct 17 ms 28496 KB Output is correct
12 Correct 16 ms 28496 KB Output is correct
13 Correct 15 ms 28496 KB Output is correct
14 Correct 17 ms 28532 KB Output is correct
15 Correct 18 ms 28516 KB Output is correct
16 Correct 15 ms 28496 KB Output is correct
17 Correct 16 ms 28532 KB Output is correct
18 Correct 16 ms 28508 KB Output is correct
19 Correct 17 ms 28528 KB Output is correct
20 Correct 16 ms 28612 KB Output is correct
21 Correct 15 ms 28480 KB Output is correct
22 Correct 15 ms 28652 KB Output is correct
23 Correct 14 ms 28624 KB Output is correct
24 Correct 16 ms 28776 KB Output is correct
25 Correct 16 ms 28776 KB Output is correct
26 Correct 18 ms 28756 KB Output is correct
27 Correct 16 ms 28700 KB Output is correct
28 Correct 16 ms 28696 KB Output is correct
29 Correct 16 ms 28668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28496 KB Output is correct
2 Correct 14 ms 28496 KB Output is correct
3 Correct 16 ms 28532 KB Output is correct
4 Correct 15 ms 28496 KB Output is correct
5 Correct 16 ms 28496 KB Output is correct
6 Correct 16 ms 28436 KB Output is correct
7 Correct 16 ms 28432 KB Output is correct
8 Correct 18 ms 28508 KB Output is correct
9 Correct 17 ms 28504 KB Output is correct
10 Correct 16 ms 28436 KB Output is correct
11 Correct 17 ms 28496 KB Output is correct
12 Correct 16 ms 28496 KB Output is correct
13 Correct 15 ms 28496 KB Output is correct
14 Correct 17 ms 28532 KB Output is correct
15 Correct 18 ms 28516 KB Output is correct
16 Correct 15 ms 28496 KB Output is correct
17 Correct 16 ms 28532 KB Output is correct
18 Correct 16 ms 28508 KB Output is correct
19 Correct 17 ms 28528 KB Output is correct
20 Correct 16 ms 28612 KB Output is correct
21 Correct 15 ms 28480 KB Output is correct
22 Correct 15 ms 28652 KB Output is correct
23 Correct 14 ms 28624 KB Output is correct
24 Correct 16 ms 28776 KB Output is correct
25 Correct 16 ms 28776 KB Output is correct
26 Correct 18 ms 28756 KB Output is correct
27 Correct 16 ms 28700 KB Output is correct
28 Correct 16 ms 28696 KB Output is correct
29 Correct 16 ms 28668 KB Output is correct
30 Correct 39 ms 32712 KB Output is correct
31 Correct 18 ms 30004 KB Output is correct
32 Correct 37 ms 36372 KB Output is correct
33 Correct 37 ms 34992 KB Output is correct
34 Correct 67 ms 37748 KB Output is correct
35 Correct 59 ms 35952 KB Output is correct
36 Correct 46 ms 35072 KB Output is correct
37 Correct 44 ms 35040 KB Output is correct
38 Correct 49 ms 34836 KB Output is correct
39 Correct 41 ms 34912 KB Output is correct
40 Correct 63 ms 37720 KB Output is correct
41 Correct 63 ms 35720 KB Output is correct
42 Correct 48 ms 35316 KB Output is correct
43 Correct 61 ms 36616 KB Output is correct
44 Correct 59 ms 36052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28496 KB Output is correct
2 Correct 14 ms 28496 KB Output is correct
3 Correct 16 ms 28532 KB Output is correct
4 Correct 15 ms 28496 KB Output is correct
5 Correct 16 ms 28496 KB Output is correct
6 Correct 16 ms 28436 KB Output is correct
7 Correct 16 ms 28432 KB Output is correct
8 Correct 18 ms 28508 KB Output is correct
9 Correct 17 ms 28504 KB Output is correct
10 Correct 16 ms 28436 KB Output is correct
11 Correct 17 ms 28496 KB Output is correct
12 Correct 16 ms 28496 KB Output is correct
13 Correct 15 ms 28496 KB Output is correct
14 Correct 17 ms 28532 KB Output is correct
15 Correct 18 ms 28516 KB Output is correct
16 Correct 15 ms 28496 KB Output is correct
17 Correct 16 ms 28532 KB Output is correct
18 Correct 16 ms 28508 KB Output is correct
19 Correct 17 ms 28528 KB Output is correct
20 Correct 16 ms 28612 KB Output is correct
21 Correct 15 ms 28480 KB Output is correct
22 Correct 15 ms 28652 KB Output is correct
23 Correct 14 ms 28624 KB Output is correct
24 Correct 16 ms 28776 KB Output is correct
25 Correct 16 ms 28776 KB Output is correct
26 Correct 18 ms 28756 KB Output is correct
27 Correct 16 ms 28700 KB Output is correct
28 Correct 16 ms 28696 KB Output is correct
29 Correct 16 ms 28668 KB Output is correct
30 Correct 39 ms 32712 KB Output is correct
31 Correct 18 ms 30004 KB Output is correct
32 Correct 37 ms 36372 KB Output is correct
33 Correct 37 ms 34992 KB Output is correct
34 Correct 67 ms 37748 KB Output is correct
35 Correct 59 ms 35952 KB Output is correct
36 Correct 46 ms 35072 KB Output is correct
37 Correct 44 ms 35040 KB Output is correct
38 Correct 49 ms 34836 KB Output is correct
39 Correct 41 ms 34912 KB Output is correct
40 Correct 63 ms 37720 KB Output is correct
41 Correct 63 ms 35720 KB Output is correct
42 Correct 48 ms 35316 KB Output is correct
43 Correct 61 ms 36616 KB Output is correct
44 Correct 59 ms 36052 KB Output is correct
45 Correct 196 ms 44972 KB Output is correct
46 Correct 24 ms 29272 KB Output is correct
47 Correct 23 ms 29548 KB Output is correct
48 Correct 349 ms 106244 KB Output is correct
49 Correct 260 ms 78492 KB Output is correct
50 Correct 920 ms 111416 KB Output is correct
51 Correct 1026 ms 103044 KB Output is correct
52 Correct 561 ms 94152 KB Output is correct
53 Correct 850 ms 94404 KB Output is correct
54 Correct 939 ms 94672 KB Output is correct
55 Correct 1318 ms 94548 KB Output is correct
56 Correct 1597 ms 95124 KB Output is correct
57 Correct 623 ms 96728 KB Output is correct
58 Correct 605 ms 97032 KB Output is correct
59 Correct 573 ms 97080 KB Output is correct
60 Correct 744 ms 97260 KB Output is correct
61 Correct 970 ms 97140 KB Output is correct
62 Correct 534 ms 99484 KB Output is correct
63 Correct 476 ms 96244 KB Output is correct
64 Correct 1303 ms 117308 KB Output is correct
65 Correct 590 ms 95000 KB Output is correct
66 Correct 534 ms 91060 KB Output is correct
67 Correct 990 ms 100276 KB Output is correct
68 Correct 198 ms 74600 KB Output is correct
69 Correct 83 ms 47848 KB Output is correct
70 Correct 953 ms 102888 KB Output is correct
71 Correct 360 ms 89740 KB Output is correct
72 Correct 298 ms 85572 KB Output is correct
73 Correct 833 ms 98204 KB Output is correct
74 Correct 1777 ms 95160 KB Output is correct
75 Correct 1364 ms 110012 KB Output is correct
76 Correct 1720 ms 107552 KB Output is correct