답안 #150702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150702 2019-09-01T08:50:10 Z Ian and 2-bit memory(#3648, percywtc, nhho, ulna) Bulb Game (FXCUP4_bulb) C++17
100 / 100
93 ms 16764 KB
#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;

bool red[300055];

void dfs(int v, vector<int> &L, vector<int> &R) {
	if (v < 0) return;

	if (L[v] == -1) {
		red[v] = true;
	}

	dfs(L[v], L, R);
	dfs(R[v], L, R);

	if (L[v] >= 0) {
		red[v] |= red[L[v]];
	}
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int N = L.size();
	int v = 0;
	vector<int> vec;

	while (v >= 0) {
		vec.push_back(v);
		v = L[v];
	}

	if (v == -2) return 0;

	dfs(0, L, R);

	vec.push_back(-1);

	for (int i = 0; i < (int)vec.size(); i++) {
		vector<int> temp;

		for (int j = 0; j <= i; j++) {
			temp.push_back(vec[j]);
		}

		if (temp.back() >= 0) {
			temp.push_back(R[temp.back()]);
		}

		while (temp.back() >= 0) {
			temp.push_back(L[temp.back()]);
		}

		if (temp.back() == -2 && temp.size() - 1 < N) continue;

		bool bad = false;

		for (int j = 0; j < (int)temp.size(); j++) {
			if (j == i) continue;
			if (temp[j] >= 0) {
				if (R[temp[j]] == -2) {
					bad = true;
					break;
				}

				if (R[temp[j]] == -1) {
					continue;
				}

				if (!red[R[temp[j]]]) {
					bad = true;
					break;
				}
			}
		}

		if (!bad) {
			return 1;
		}
	}

	return 0;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:52:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (temp.back() == -2 && temp.size() - 1 < N) continue;
                            ~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 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 376 KB Output is correct
5 Correct 2 ms 292 KB Output is correct
6 Correct 2 ms 252 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 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 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 292 KB Output is correct
8 Correct 2 ms 252 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 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 376 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 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 380 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 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 292 KB Output is correct
8 Correct 2 ms 252 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 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 376 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 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 380 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 70 ms 6168 KB Output is correct
28 Correct 80 ms 6412 KB Output is correct
29 Correct 83 ms 6428 KB Output is correct
30 Correct 92 ms 16764 KB Output is correct
31 Correct 93 ms 16532 KB Output is correct
32 Correct 83 ms 6128 KB Output is correct
33 Correct 82 ms 6812 KB Output is correct
34 Correct 81 ms 7132 KB Output is correct
35 Correct 82 ms 6136 KB Output is correct
36 Correct 83 ms 6508 KB Output is correct
37 Correct 82 ms 6172 KB Output is correct
38 Correct 82 ms 6560 KB Output is correct
39 Correct 82 ms 6648 KB Output is correct
40 Correct 82 ms 5904 KB Output is correct
41 Correct 82 ms 5752 KB Output is correct
42 Correct 82 ms 6540 KB Output is correct
43 Correct 82 ms 6748 KB Output is correct
44 Correct 83 ms 6492 KB Output is correct
45 Correct 82 ms 6180 KB Output is correct
46 Correct 81 ms 6428 KB Output is correct
47 Correct 83 ms 8332 KB Output is correct
48 Correct 84 ms 8944 KB Output is correct
49 Correct 84 ms 9028 KB Output is correct
50 Correct 83 ms 7792 KB Output is correct