답안 #602287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602287 2022-07-22T20:44:50 Z patrikpavic2 게임 (APIO22_game) C++17
30 / 100
4000 ms 28088 KB
#include "game.h"
#include <vector>
#include <cstdio>
#define PB push_back
 
using namespace std;
 
const int N = 5e5 + 500;
const int BUK = 400;
 
int n, k, ans;
vector < int > v[N], r[N];
int L[N], R[N], bukL[N], bukR[N], rac[N], bio[N], cookie;
 
void init(int _n, int _k) {
	n = _n, k = _k;
	for(int i = 0;i < n;i++)
		L[i] = -1, R[i] = n, bukL[i] = -1, bukR[i] = k;
	for(int i = 0;i < k;i++)
		L[i] = i, R[i] = i, bukL[i] = i / BUK, bukR[i] = i / BUK, rac[i] = 1;
}
 
void buk_noviL(int x, int vr){
	bukL[x] = vr;
	for(int y : v[x]) 
		if(bukL[y] < vr) buk_noviL(y, vr);
}
 
void buk_noviR(int x, int vr){
	bukR[x] = vr;
	for(int y : r[x])
		if(bukR[y] > vr) buk_noviR(y, vr);
}
 
void noviL(int x, int vr){
	L[x] = vr;
	for(int y : v[x]) 
		if(L[y] < vr && bukR[y] <= vr / BUK) noviL(y, vr);
}
 
void stariL(int x){
	if(bio[x] == cookie) return;
	bio[x] = cookie;
	for(int y : r[x]){
		if(bukL[y] < bukL[x]) continue;
		stariL(y); L[x] = max(L[x], L[y]);
	}
}
 
void stariR(int x){
	if(bio[x] == cookie) return;
	bio[x] = cookie;
	for(int y : v[x]){
		if(bukR[y] > bukR[x]) continue;
		stariR(y); R[x] = min(R[x], R[y]);
	}
}
 
void noviR(int x, int vr){
	R[x] = vr;
	for(int y : r[x])
		if(R[y] > vr && bukL[y] >= vr / BUK) noviR(y, vr);
}
 
void update(int a){
	if(bukL[a] == bukR[a] && !rac[a]){
		cookie++; stariL(a); 
		cookie++; stariR(a); 
		//rac[a] = 1;
	}
}
 
int add_teleporter(int a, int b) {
	v[a].PB(b), r[b].PB(a);
	if(a == b && a < k) ans = 1;
	if(bukL[b] < bukL[a]) buk_noviL(b, bukL[a]);
	if(bukR[a] > bukR[b]) buk_noviR(a, bukR[b]);
		
	ans |= bukL[a] > bukR[a];
	ans |= bukL[b] > bukR[b];
	if(L[b] < L[a] && bukR[b] <= L[a] / BUK) noviL(b, L[a]);
	if(R[a] > R[b] && bukL[a] >= R[b] / BUK) noviR(a, R[b]);
	update(a); update(b);
	if(a >= k) ans |= L[a] == R[a];
	if(b >= k) ans |= L[b] == R[b];
	ans |= L[a] > R[a];
	ans |= L[b] > R[b];
	
	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23712 KB Output is correct
2 Correct 11 ms 23732 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 12 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 11 ms 23720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23712 KB Output is correct
2 Correct 11 ms 23732 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 12 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 11 ms 23720 KB Output is correct
8 Correct 12 ms 23712 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 14 ms 23760 KB Output is correct
11 Correct 27 ms 23788 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23720 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 14 ms 23760 KB Output is correct
16 Correct 15 ms 23760 KB Output is correct
17 Correct 13 ms 23804 KB Output is correct
18 Correct 14 ms 23764 KB Output is correct
19 Correct 16 ms 23804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23712 KB Output is correct
2 Correct 11 ms 23732 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 12 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 11 ms 23720 KB Output is correct
8 Correct 12 ms 23712 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 14 ms 23760 KB Output is correct
11 Correct 27 ms 23788 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23720 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 14 ms 23760 KB Output is correct
16 Correct 15 ms 23760 KB Output is correct
17 Correct 13 ms 23804 KB Output is correct
18 Correct 14 ms 23764 KB Output is correct
19 Correct 16 ms 23804 KB Output is correct
20 Correct 17 ms 23888 KB Output is correct
21 Correct 13 ms 23864 KB Output is correct
22 Correct 15 ms 23868 KB Output is correct
23 Correct 14 ms 23896 KB Output is correct
24 Correct 19 ms 23940 KB Output is correct
25 Correct 20 ms 23864 KB Output is correct
26 Correct 80 ms 23940 KB Output is correct
27 Correct 19 ms 23856 KB Output is correct
28 Correct 18 ms 23880 KB Output is correct
29 Correct 17 ms 23876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23712 KB Output is correct
2 Correct 11 ms 23732 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 12 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 11 ms 23720 KB Output is correct
8 Correct 12 ms 23712 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 14 ms 23760 KB Output is correct
11 Correct 27 ms 23788 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23720 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 14 ms 23760 KB Output is correct
16 Correct 15 ms 23760 KB Output is correct
17 Correct 13 ms 23804 KB Output is correct
18 Correct 14 ms 23764 KB Output is correct
19 Correct 16 ms 23804 KB Output is correct
20 Correct 17 ms 23888 KB Output is correct
21 Correct 13 ms 23864 KB Output is correct
22 Correct 15 ms 23868 KB Output is correct
23 Correct 14 ms 23896 KB Output is correct
24 Correct 19 ms 23940 KB Output is correct
25 Correct 20 ms 23864 KB Output is correct
26 Correct 80 ms 23940 KB Output is correct
27 Correct 19 ms 23856 KB Output is correct
28 Correct 18 ms 23880 KB Output is correct
29 Correct 17 ms 23876 KB Output is correct
30 Correct 32 ms 25500 KB Output is correct
31 Correct 30 ms 24680 KB Output is correct
32 Correct 63 ms 27080 KB Output is correct
33 Correct 32 ms 26172 KB Output is correct
34 Correct 564 ms 28072 KB Output is correct
35 Correct 169 ms 26952 KB Output is correct
36 Correct 2843 ms 26388 KB Output is correct
37 Correct 2150 ms 26360 KB Output is correct
38 Correct 373 ms 25992 KB Output is correct
39 Correct 801 ms 26204 KB Output is correct
40 Correct 476 ms 28088 KB Output is correct
41 Correct 88 ms 26536 KB Output is correct
42 Correct 82 ms 26252 KB Output is correct
43 Execution timed out 4094 ms 27068 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23712 KB Output is correct
2 Correct 11 ms 23732 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 12 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 11 ms 23720 KB Output is correct
8 Correct 12 ms 23712 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 14 ms 23760 KB Output is correct
11 Correct 27 ms 23788 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23720 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 14 ms 23760 KB Output is correct
16 Correct 15 ms 23760 KB Output is correct
17 Correct 13 ms 23804 KB Output is correct
18 Correct 14 ms 23764 KB Output is correct
19 Correct 16 ms 23804 KB Output is correct
20 Correct 17 ms 23888 KB Output is correct
21 Correct 13 ms 23864 KB Output is correct
22 Correct 15 ms 23868 KB Output is correct
23 Correct 14 ms 23896 KB Output is correct
24 Correct 19 ms 23940 KB Output is correct
25 Correct 20 ms 23864 KB Output is correct
26 Correct 80 ms 23940 KB Output is correct
27 Correct 19 ms 23856 KB Output is correct
28 Correct 18 ms 23880 KB Output is correct
29 Correct 17 ms 23876 KB Output is correct
30 Correct 32 ms 25500 KB Output is correct
31 Correct 30 ms 24680 KB Output is correct
32 Correct 63 ms 27080 KB Output is correct
33 Correct 32 ms 26172 KB Output is correct
34 Correct 564 ms 28072 KB Output is correct
35 Correct 169 ms 26952 KB Output is correct
36 Correct 2843 ms 26388 KB Output is correct
37 Correct 2150 ms 26360 KB Output is correct
38 Correct 373 ms 25992 KB Output is correct
39 Correct 801 ms 26204 KB Output is correct
40 Correct 476 ms 28088 KB Output is correct
41 Correct 88 ms 26536 KB Output is correct
42 Correct 82 ms 26252 KB Output is correct
43 Execution timed out 4094 ms 27068 KB Time limit exceeded
44 Halted 0 ms 0 KB -