Submission #760088

# Submission time Handle Problem Language Result Execution time Memory
760088 2023-06-17T07:23:51 Z jk410 Bulb Game (FXCUP4_bulb) C++17
100 / 100
77 ms 34764 KB
#include <bits/stdc++.h>
#include "bulb.h"
using namespace std;

bool flag = false;
int n;
vector<int> l, r;
vector<int> ans;

void update(int lx, int rx, int v) {
	ans[lx] += v;
	ans[rx + 1] -= v;
}

int dfs(int cur, int f, int s, int cnt) {
	if (cur == -1)
		return 0;
	if (cur == -2) {
		if (f == -1) {
			flag = true;
			return 0;
		}
		else if (s == -1) {
			if (cnt == n)
				return 0;
			update(0, n - 1, 1);
			update(f, f, 1);
			return 1;
		}
		update(f, f, 1);
		update(s, s, 1);
		return 0;
	}
	int tmp = 0;
	tmp += dfs(l[cur], f, s, cnt + 1);
	int nf = f, ns = s;
	if (ns == -1) {
		if (nf == -1)
			nf = cur;
		else
			ns = cur;
		tmp += dfs(r[cur], nf, ns, cnt + 1);
	}
	update(cur, cur, -tmp);
	return tmp;
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	n = (int)L.size();
	l = L;
	r = R;
	ans.resize(n + 1);
	dfs(0, -1, -1, 0);
	for (int i = 1; i < n; i++)
		ans[i] += ans[i - 1];
	if (flag)
		return 0;
	for (int i = 0; i < n; i++) {
		if (!ans[i])
			return 1;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 47 ms 11208 KB Output is correct
28 Correct 44 ms 11212 KB Output is correct
29 Correct 40 ms 11336 KB Output is correct
30 Correct 63 ms 34764 KB Output is correct
31 Correct 57 ms 34756 KB Output is correct
32 Correct 42 ms 11212 KB Output is correct
33 Correct 40 ms 11340 KB Output is correct
34 Correct 42 ms 11332 KB Output is correct
35 Correct 44 ms 11328 KB Output is correct
36 Correct 46 ms 11208 KB Output is correct
37 Correct 41 ms 11308 KB Output is correct
38 Correct 40 ms 11216 KB Output is correct
39 Correct 41 ms 11320 KB Output is correct
40 Correct 40 ms 11336 KB Output is correct
41 Correct 40 ms 11216 KB Output is correct
42 Correct 74 ms 11212 KB Output is correct
43 Correct 43 ms 11328 KB Output is correct
44 Correct 40 ms 11324 KB Output is correct
45 Correct 41 ms 11328 KB Output is correct
46 Correct 77 ms 11224 KB Output is correct
47 Correct 52 ms 16464 KB Output is correct
48 Correct 49 ms 16456 KB Output is correct
49 Correct 50 ms 16460 KB Output is correct
50 Correct 48 ms 16456 KB Output is correct