답안 #817005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817005 2023-08-09T08:21:35 Z 이종영(#10379) 게임 (APIO22_game) C++17
60 / 100
4000 ms 135160 KB
#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=30;
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;
	debug(u,d[m],0,m);
	if(in[u][d[m]][1]){
		debug(u); 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);
		for(int v: gr[u]) if(in[v][d[m]+1][1]==lc[m]) wait[lc[m]][1].emplace_back(u);
	}
	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;
	debug(u,d[m],1,m);
	if(in[u][d[m]][0]){
		debug(u); 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);
		for(int v: gr[u]) if(in[v][d[m]+1][1]==rc[m]) wait[rc[m]][1].emplace_back(u);
	}
	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;
	}
	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++;
	debug(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;
}

Compilation message

game.cpp: In function 'bool dfsr(int, int)':
game.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
game.cpp:45:2: note: in expansion of macro 'debug'
   45 |  debug(u,d[m],0,m);
      |  ^~~~~
game.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
game.cpp:47:3: note: in expansion of macro 'debug'
   47 |   debug(u); return 1;
      |   ^~~~~
game.cpp: In function 'bool dfs(int, int)':
game.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
game.cpp:61:2: note: in expansion of macro 'debug'
   61 |  debug(u,d[m],1,m);
      |  ^~~~~
game.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
game.cpp:63:3: note: in expansion of macro 'debug'
   63 |   debug(u); return 1;
      |   ^~~~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
game.cpp:117:2: note: in expansion of macro 'debug'
  117 |  debug(u,v);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28496 KB Output is correct
2 Correct 14 ms 28504 KB Output is correct
3 Correct 13 ms 28468 KB Output is correct
4 Correct 13 ms 28468 KB Output is correct
5 Correct 13 ms 28544 KB Output is correct
6 Correct 12 ms 28460 KB Output is correct
7 Correct 13 ms 28496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28496 KB Output is correct
2 Correct 14 ms 28504 KB Output is correct
3 Correct 13 ms 28468 KB Output is correct
4 Correct 13 ms 28468 KB Output is correct
5 Correct 13 ms 28544 KB Output is correct
6 Correct 12 ms 28460 KB Output is correct
7 Correct 13 ms 28496 KB Output is correct
8 Correct 12 ms 28496 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 12 ms 28476 KB Output is correct
11 Correct 13 ms 28540 KB Output is correct
12 Correct 13 ms 28440 KB Output is correct
13 Correct 12 ms 28496 KB Output is correct
14 Correct 13 ms 28496 KB Output is correct
15 Correct 15 ms 28548 KB Output is correct
16 Correct 14 ms 28480 KB Output is correct
17 Correct 13 ms 28544 KB Output is correct
18 Correct 15 ms 28476 KB Output is correct
19 Correct 12 ms 28472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28496 KB Output is correct
2 Correct 14 ms 28504 KB Output is correct
3 Correct 13 ms 28468 KB Output is correct
4 Correct 13 ms 28468 KB Output is correct
5 Correct 13 ms 28544 KB Output is correct
6 Correct 12 ms 28460 KB Output is correct
7 Correct 13 ms 28496 KB Output is correct
8 Correct 12 ms 28496 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 12 ms 28476 KB Output is correct
11 Correct 13 ms 28540 KB Output is correct
12 Correct 13 ms 28440 KB Output is correct
13 Correct 12 ms 28496 KB Output is correct
14 Correct 13 ms 28496 KB Output is correct
15 Correct 15 ms 28548 KB Output is correct
16 Correct 14 ms 28480 KB Output is correct
17 Correct 13 ms 28544 KB Output is correct
18 Correct 15 ms 28476 KB Output is correct
19 Correct 12 ms 28472 KB Output is correct
20 Correct 12 ms 28752 KB Output is correct
21 Correct 13 ms 28588 KB Output is correct
22 Correct 13 ms 28804 KB Output is correct
23 Correct 14 ms 28692 KB Output is correct
24 Correct 14 ms 28752 KB Output is correct
25 Correct 16 ms 28788 KB Output is correct
26 Correct 16 ms 28800 KB Output is correct
27 Correct 18 ms 28740 KB Output is correct
28 Correct 14 ms 28756 KB Output is correct
29 Correct 15 ms 28808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28496 KB Output is correct
2 Correct 14 ms 28504 KB Output is correct
3 Correct 13 ms 28468 KB Output is correct
4 Correct 13 ms 28468 KB Output is correct
5 Correct 13 ms 28544 KB Output is correct
6 Correct 12 ms 28460 KB Output is correct
7 Correct 13 ms 28496 KB Output is correct
8 Correct 12 ms 28496 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 12 ms 28476 KB Output is correct
11 Correct 13 ms 28540 KB Output is correct
12 Correct 13 ms 28440 KB Output is correct
13 Correct 12 ms 28496 KB Output is correct
14 Correct 13 ms 28496 KB Output is correct
15 Correct 15 ms 28548 KB Output is correct
16 Correct 14 ms 28480 KB Output is correct
17 Correct 13 ms 28544 KB Output is correct
18 Correct 15 ms 28476 KB Output is correct
19 Correct 12 ms 28472 KB Output is correct
20 Correct 12 ms 28752 KB Output is correct
21 Correct 13 ms 28588 KB Output is correct
22 Correct 13 ms 28804 KB Output is correct
23 Correct 14 ms 28692 KB Output is correct
24 Correct 14 ms 28752 KB Output is correct
25 Correct 16 ms 28788 KB Output is correct
26 Correct 16 ms 28800 KB Output is correct
27 Correct 18 ms 28740 KB Output is correct
28 Correct 14 ms 28756 KB Output is correct
29 Correct 15 ms 28808 KB Output is correct
30 Correct 36 ms 33292 KB Output is correct
31 Correct 19 ms 30092 KB Output is correct
32 Correct 32 ms 38696 KB Output is correct
33 Correct 31 ms 37108 KB Output is correct
34 Correct 44 ms 40104 KB Output is correct
35 Correct 350 ms 38540 KB Output is correct
36 Correct 125 ms 37508 KB Output is correct
37 Correct 219 ms 37616 KB Output is correct
38 Correct 432 ms 37300 KB Output is correct
39 Correct 499 ms 37272 KB Output is correct
40 Correct 72 ms 40132 KB Output is correct
41 Correct 400 ms 38284 KB Output is correct
42 Correct 217 ms 37768 KB Output is correct
43 Correct 54 ms 38920 KB Output is correct
44 Correct 56 ms 38292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28496 KB Output is correct
2 Correct 14 ms 28504 KB Output is correct
3 Correct 13 ms 28468 KB Output is correct
4 Correct 13 ms 28468 KB Output is correct
5 Correct 13 ms 28544 KB Output is correct
6 Correct 12 ms 28460 KB Output is correct
7 Correct 13 ms 28496 KB Output is correct
8 Correct 12 ms 28496 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 12 ms 28476 KB Output is correct
11 Correct 13 ms 28540 KB Output is correct
12 Correct 13 ms 28440 KB Output is correct
13 Correct 12 ms 28496 KB Output is correct
14 Correct 13 ms 28496 KB Output is correct
15 Correct 15 ms 28548 KB Output is correct
16 Correct 14 ms 28480 KB Output is correct
17 Correct 13 ms 28544 KB Output is correct
18 Correct 15 ms 28476 KB Output is correct
19 Correct 12 ms 28472 KB Output is correct
20 Correct 12 ms 28752 KB Output is correct
21 Correct 13 ms 28588 KB Output is correct
22 Correct 13 ms 28804 KB Output is correct
23 Correct 14 ms 28692 KB Output is correct
24 Correct 14 ms 28752 KB Output is correct
25 Correct 16 ms 28788 KB Output is correct
26 Correct 16 ms 28800 KB Output is correct
27 Correct 18 ms 28740 KB Output is correct
28 Correct 14 ms 28756 KB Output is correct
29 Correct 15 ms 28808 KB Output is correct
30 Correct 36 ms 33292 KB Output is correct
31 Correct 19 ms 30092 KB Output is correct
32 Correct 32 ms 38696 KB Output is correct
33 Correct 31 ms 37108 KB Output is correct
34 Correct 44 ms 40104 KB Output is correct
35 Correct 350 ms 38540 KB Output is correct
36 Correct 125 ms 37508 KB Output is correct
37 Correct 219 ms 37616 KB Output is correct
38 Correct 432 ms 37300 KB Output is correct
39 Correct 499 ms 37272 KB Output is correct
40 Correct 72 ms 40132 KB Output is correct
41 Correct 400 ms 38284 KB Output is correct
42 Correct 217 ms 37768 KB Output is correct
43 Correct 54 ms 38920 KB Output is correct
44 Correct 56 ms 38292 KB Output is correct
45 Correct 184 ms 45004 KB Output is correct
46 Correct 25 ms 29384 KB Output is correct
47 Correct 23 ms 29780 KB Output is correct
48 Correct 343 ms 127680 KB Output is correct
49 Correct 261 ms 83900 KB Output is correct
50 Correct 891 ms 135160 KB Output is correct
51 Execution timed out 4107 ms 109872 KB Time limit exceeded
52 Halted 0 ms 0 KB -