Submission #148865

# Submission time Handle Problem Language Result Execution time Memory
148865 2019-09-01T05:17:08 Z 본인 하지만 안 어림 ㅋㅋ(#3569, gs13105, xdoju, gs13068) Bulb Game (FXCUP4_bulb) C++17
100 / 100
109 ms 23848 KB
#include "bulb.h"

using namespace std;

int d[300003], D[300003];
int c[300003];
int b[300003];

void dfs1(int x, vector<int> &L) {
	d[x] = L[x];
	D[x] = 1;
	if (d[x] >= 0) {
		dfs1(d[x], L);
		D[x] += D[d[x]];
		d[x] = d[d[x]];
	}
}

void dfs2(int x, vector<int> &L, vector<int> &R) {
	if (L[x] >= 0) dfs2(L[x], L, R);
	if (R[x] >= 0) dfs2(R[x], L, R);
	c[x] = R[x] == -2 || d[R[x]] == -2 || (L[x] >= 0 && c[L[x]] == -2) ? -2 : -1;
	b[x] = R[x] == -1 || d[R[x]] == -1 || (L[x] >= 0 && b[L[x]] == -1) ? -1 : -2;
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int i, j, k, t, N = L.size();
	for (i = 0; i < N; i++) if (!d[i]) dfs1(i, L);
	if (d[0] == -2) return 0;
	dfs2(0, L, R);
	for (i = 0, j = 1; i >= 0; i = L[i], j++) {
		if (j == N || R[i] == -1 || (R[i] >= 0 && c[R[i]] == -1 && (d[R[i]] == -1 || j + D[R[i]] == N))) return 1;
		if (R[i] == -2 || R[i] >= 0 && d[R[i]] == -2) break;
	}
	t = D[0];
	for (i = j = k = 0; i >= 0; i = L[i]) {
		if (R[i] == -2) return 0;
		if (R[i] >= 0) {
			if (d[R[i]] == -2 && b[R[i]] == -2) return 0;
			t += D[R[i]];
			if (b[R[i]] == -1) k++;
			if (d[R[i]] != -1) j++;
		}
	}
	return j <= 1 && k + N - t >= 1;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:33:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (R[i] == -2 || R[i] >= 0 && d[R[i]] == -2) break;
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 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 380 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 392 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 392 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 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 380 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 392 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 392 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 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 79 ms 7332 KB Output is correct
28 Correct 93 ms 9720 KB Output is correct
29 Correct 96 ms 9628 KB Output is correct
30 Correct 109 ms 23708 KB Output is correct
31 Correct 109 ms 23848 KB Output is correct
32 Correct 96 ms 9884 KB Output is correct
33 Correct 97 ms 9756 KB Output is correct
34 Correct 98 ms 9768 KB Output is correct
35 Correct 99 ms 9852 KB Output is correct
36 Correct 97 ms 9752 KB Output is correct
37 Correct 98 ms 9896 KB Output is correct
38 Correct 99 ms 9872 KB Output is correct
39 Correct 101 ms 9844 KB Output is correct
40 Correct 99 ms 9880 KB Output is correct
41 Correct 100 ms 9960 KB Output is correct
42 Correct 98 ms 9872 KB Output is correct
43 Correct 101 ms 9988 KB Output is correct
44 Correct 97 ms 9884 KB Output is correct
45 Correct 98 ms 9964 KB Output is correct
46 Correct 98 ms 10008 KB Output is correct
47 Correct 98 ms 13044 KB Output is correct
48 Correct 99 ms 13124 KB Output is correct
49 Correct 96 ms 13080 KB Output is correct
50 Correct 98 ms 12820 KB Output is correct