Submission #760087

# Submission time Handle Problem Language Result Execution time Memory
760087 2023-06-17T07:23:19 Z jk410 Bulb Game (FXCUP4_bulb) C++17
0 / 100
1 ms 212 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) {
		flag = true;
		return 0;
	}
	if (cur == -2) {
		if (f == -1)
			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 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -