답안 #602319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602319 2022-07-22T21:45:36 Z patrikpavic2 게임 (APIO22_game) C++17
60 / 100
4000 ms 59176 KB
#include "game.h"
#include <vector>
#include <cstdio>
#include <list>
#define PB push_back
 
using namespace std;
 
const int N = 5e5 + 500;
const int BUK = 700;
 
int n, k, ans;
vector < int > v[N], r[N];
int L[N], R[N], bukL[N], bukR[N], racL[N], racR[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, racL[i] = 1, racR[i] = 1;
}


int KOLKO_buk_noviL, KOLKO_buk_noviR;
int KOLKO_noviL, KOLKO_noviR;
int KOLKO_stariL, KOLKO_stariR;

 
void buk_noviL(int x, int vr){
	KOLKO_buk_noviL++;
	bukL[x] = vr;
	for(int y : v[x]) 
		if(bukL[y] < vr) buk_noviL(y, vr);
}
 
void buk_noviR(int x, int vr){
	KOLKO_buk_noviR++;
	bukR[x] = vr;
	for(int y : r[x])
		if(bukR[y] > vr) buk_noviR(y, vr);
}
 
void noviL(int x, int vr){
	KOLKO_noviL++;
	L[x] = vr;
	for(int y : v[x]) 
		if(L[y] < vr && bukR[y] <= vr / BUK) noviL(y, vr);
}
 
void stariL(int x){
	KOLKO_stariL++;
	if(bio[x] == cookie || racL[x]) return;
	bio[x] = cookie;
	for(int y : r[x]){
		if(bukL[y] < bukL[x]) continue;
		stariL(y); L[x] = max(L[x], L[y]);
	}
	racL[x] = 1;
}
 
void stariR(int x){
	KOLKO_stariR++;
	if(bio[x] == cookie || racR[x]) return;
	bio[x] = cookie;
	for(int y : v[x]){
		if(bukR[y] > bukR[x]) continue;
		stariR(y); R[x] = min(R[x], R[y]);
	}
	racR[x] = 1;
	
}

void cistiL(int x){
	if(bio[x] != cookie - 1) return;
	bio[x] = cookie;
	for(int y : r[x]){
		cistiL(y); L[x] = max(L[x], L[y]);
	}
}

void cistiR(int x){
	if(bio[x] != cookie - 1) return;
	bio[x] = cookie;
	for(int y : v[x]){
		cistiR(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] && !racL[a]){
		cookie++; stariL(a); 
		cookie++; cistiL(a);
	}
	if(bukL[a] == bukR[a] && !racR[a]){	
		cookie++; stariR(a); 
		cookie++; cistiR(a);
	}
}

int cnt = 0;
 
int add_teleporter(int a, int b) {
	if(ans) return ans;
	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];
	update(a); update(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]);
	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];
	/**
	printf("%d --> %d\n", a, b);
	printf("buk[ %d ] = %d %d\n", a, bukL[a], bukR[a]);
	printf("buk[ %d ] = %d %d\n", b, bukL[b], bukR[b]);
	printf("LR [ %d ] = %d %d\n", a, L[a], R[a]);
	printf("LR [ %d ] = %d %d\n", b, L[b], R[b]);	
	printf("%d %d\n", KOLKO_buk_noviL, KOLKO_buk_noviR);
	printf("%d %d\n", KOLKO_noviL, KOLKO_noviR);
	printf("%d %d\n", KOLKO_stariL, KOLKO_stariR);
	printf("\n");
	KOLKO_buk_noviL = 0, KOLKO_buk_noviR = 0;
	KOLKO_noviL = 0, KOLKO_noviR = 0;
	KOLKO_stariL = 0, KOLKO_stariR = 0;
	**/
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23828 KB Output is correct
5 Correct 11 ms 23856 KB Output is correct
6 Correct 13 ms 23804 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23828 KB Output is correct
5 Correct 11 ms 23856 KB Output is correct
6 Correct 13 ms 23804 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Correct 12 ms 23816 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 13 ms 23772 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 12 ms 23760 KB Output is correct
13 Correct 12 ms 23836 KB Output is correct
14 Correct 13 ms 23760 KB Output is correct
15 Correct 11 ms 23740 KB Output is correct
16 Correct 11 ms 23760 KB Output is correct
17 Correct 14 ms 23804 KB Output is correct
18 Correct 12 ms 23760 KB Output is correct
19 Correct 14 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23828 KB Output is correct
5 Correct 11 ms 23856 KB Output is correct
6 Correct 13 ms 23804 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Correct 12 ms 23816 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 13 ms 23772 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 12 ms 23760 KB Output is correct
13 Correct 12 ms 23836 KB Output is correct
14 Correct 13 ms 23760 KB Output is correct
15 Correct 11 ms 23740 KB Output is correct
16 Correct 11 ms 23760 KB Output is correct
17 Correct 14 ms 23804 KB Output is correct
18 Correct 12 ms 23760 KB Output is correct
19 Correct 14 ms 23888 KB Output is correct
20 Correct 12 ms 24036 KB Output is correct
21 Correct 12 ms 23816 KB Output is correct
22 Correct 13 ms 23836 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 16 ms 23852 KB Output is correct
25 Correct 16 ms 23896 KB Output is correct
26 Correct 14 ms 23848 KB Output is correct
27 Correct 13 ms 23876 KB Output is correct
28 Correct 12 ms 23888 KB Output is correct
29 Correct 13 ms 23920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23828 KB Output is correct
5 Correct 11 ms 23856 KB Output is correct
6 Correct 13 ms 23804 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Correct 12 ms 23816 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 13 ms 23772 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 12 ms 23760 KB Output is correct
13 Correct 12 ms 23836 KB Output is correct
14 Correct 13 ms 23760 KB Output is correct
15 Correct 11 ms 23740 KB Output is correct
16 Correct 11 ms 23760 KB Output is correct
17 Correct 14 ms 23804 KB Output is correct
18 Correct 12 ms 23760 KB Output is correct
19 Correct 14 ms 23888 KB Output is correct
20 Correct 12 ms 24036 KB Output is correct
21 Correct 12 ms 23816 KB Output is correct
22 Correct 13 ms 23836 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 16 ms 23852 KB Output is correct
25 Correct 16 ms 23896 KB Output is correct
26 Correct 14 ms 23848 KB Output is correct
27 Correct 13 ms 23876 KB Output is correct
28 Correct 12 ms 23888 KB Output is correct
29 Correct 13 ms 23920 KB Output is correct
30 Correct 36 ms 25520 KB Output is correct
31 Correct 18 ms 24736 KB Output is correct
32 Correct 35 ms 27412 KB Output is correct
33 Correct 39 ms 26412 KB Output is correct
34 Correct 482 ms 28312 KB Output is correct
35 Correct 190 ms 27136 KB Output is correct
36 Correct 46 ms 26460 KB Output is correct
37 Correct 44 ms 26464 KB Output is correct
38 Correct 42 ms 26288 KB Output is correct
39 Correct 47 ms 26288 KB Output is correct
40 Correct 389 ms 28336 KB Output is correct
41 Correct 103 ms 26784 KB Output is correct
42 Correct 86 ms 26552 KB Output is correct
43 Correct 80 ms 28580 KB Output is correct
44 Correct 236 ms 28000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 11 ms 23760 KB Output is correct
4 Correct 11 ms 23828 KB Output is correct
5 Correct 11 ms 23856 KB Output is correct
6 Correct 13 ms 23804 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Correct 12 ms 23816 KB Output is correct
9 Correct 12 ms 23760 KB Output is correct
10 Correct 13 ms 23772 KB Output is correct
11 Correct 12 ms 23760 KB Output is correct
12 Correct 12 ms 23760 KB Output is correct
13 Correct 12 ms 23836 KB Output is correct
14 Correct 13 ms 23760 KB Output is correct
15 Correct 11 ms 23740 KB Output is correct
16 Correct 11 ms 23760 KB Output is correct
17 Correct 14 ms 23804 KB Output is correct
18 Correct 12 ms 23760 KB Output is correct
19 Correct 14 ms 23888 KB Output is correct
20 Correct 12 ms 24036 KB Output is correct
21 Correct 12 ms 23816 KB Output is correct
22 Correct 13 ms 23836 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 16 ms 23852 KB Output is correct
25 Correct 16 ms 23896 KB Output is correct
26 Correct 14 ms 23848 KB Output is correct
27 Correct 13 ms 23876 KB Output is correct
28 Correct 12 ms 23888 KB Output is correct
29 Correct 13 ms 23920 KB Output is correct
30 Correct 36 ms 25520 KB Output is correct
31 Correct 18 ms 24736 KB Output is correct
32 Correct 35 ms 27412 KB Output is correct
33 Correct 39 ms 26412 KB Output is correct
34 Correct 482 ms 28312 KB Output is correct
35 Correct 190 ms 27136 KB Output is correct
36 Correct 46 ms 26460 KB Output is correct
37 Correct 44 ms 26464 KB Output is correct
38 Correct 42 ms 26288 KB Output is correct
39 Correct 47 ms 26288 KB Output is correct
40 Correct 389 ms 28336 KB Output is correct
41 Correct 103 ms 26784 KB Output is correct
42 Correct 86 ms 26552 KB Output is correct
43 Correct 80 ms 28580 KB Output is correct
44 Correct 236 ms 28000 KB Output is correct
45 Correct 279 ms 40288 KB Output is correct
46 Correct 24 ms 28896 KB Output is correct
47 Correct 19 ms 28812 KB Output is correct
48 Correct 510 ms 59176 KB Output is correct
49 Correct 330 ms 50476 KB Output is correct
50 Execution timed out 4086 ms 49952 KB Time limit exceeded
51 Halted 0 ms 0 KB -