답안 #150278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150278 2019-09-01T08:03:13 Z etyu(#3586, kimjihoon) Bulb Game (FXCUP4_bulb) C++17
100 / 100
100 ms 19492 KB
#include "bulb.h"
#include <vector>
#include <iostream>
using namespace std;

int pl[300009], st[300009];
bool d[300009];
std::vector<int> l, r;

void dp(int n)
{
	if (pl[n] != 0) return;
	st[n] = 1;
	if (l[n] < 0) pl[n] = l[n];
	else {
		dp(l[n]);
		pl[n] = pl[l[n]];
		st[n] += st[l[n]];
	}
	if (r[n] >= 0) {
		dp(r[n]);
		st[n] += st[r[n]];
	}
	if ((l[n] >= 0 && d[l[n]]) || (r[n] == -2 || (r[n] >= 0 && pl[r[n]] == -2))) d[n] = true;
	else d[n] = false;
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int N = L.size();
	l = L; r = R;
	int rt = 0;
	for (int i = 0; i < N; i++) 
		if (pl[i] == 0) {
			dp(i);
			rt = i;
		}
	int hn = rt;
	while (hn >= 0)
		hn = l[hn];
	if (hn == -2) return 0;
	hn = rt;
	int sp = 0;
	while (hn >= 0) {
		int ts = sp;
		if (l[hn] >= 0) ts += st[l[hn]];
		bool f = true;
		if (ts != 0 && (r[hn] == -2 || (r[hn] >= 0 && pl[r[hn]] == -2))) f = false;
		if (r[hn] >= 0 && d[r[hn]]) f = false;
		if (f) return 1;
		if (r[hn] == -2 || (r[hn] >= 0 && pl[r[hn]] == -2)) return 0;
		if (r[hn] >= 0) sp += st[r[hn]];
		hn = l[hn];
	}
	return (sp != 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 352 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 352 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 292 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 352 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 292 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 89 ms 10016 KB Output is correct
28 Correct 87 ms 10024 KB Output is correct
29 Correct 89 ms 10016 KB Output is correct
30 Correct 97 ms 19492 KB Output is correct
31 Correct 100 ms 19360 KB Output is correct
32 Correct 90 ms 10016 KB Output is correct
33 Correct 89 ms 10020 KB Output is correct
34 Correct 91 ms 10020 KB Output is correct
35 Correct 90 ms 9952 KB Output is correct
36 Correct 91 ms 10020 KB Output is correct
37 Correct 89 ms 9948 KB Output is correct
38 Correct 89 ms 10056 KB Output is correct
39 Correct 89 ms 9948 KB Output is correct
40 Correct 91 ms 9964 KB Output is correct
41 Correct 90 ms 9976 KB Output is correct
42 Correct 90 ms 10016 KB Output is correct
43 Correct 91 ms 9948 KB Output is correct
44 Correct 91 ms 9976 KB Output is correct
45 Correct 90 ms 10032 KB Output is correct
46 Correct 90 ms 10016 KB Output is correct
47 Correct 92 ms 12112 KB Output is correct
48 Correct 91 ms 12024 KB Output is correct
49 Correct 92 ms 12024 KB Output is correct
50 Correct 92 ms 12124 KB Output is correct