Submission #148940

#TimeUsernameProblemLanguageResultExecution timeMemory
148940모현보유국 (#200)Bulb Game (FXCUP4_bulb)C++17
0 / 100
9 ms7544 KiB
#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;

const int R = -1;
const int B = -2;
typedef pair<int, int> p;

vector<int> g[303030]; //R -1 B -2
p color[303030];

void dfs(int v){
	if(g[v][0] < 0){
		color[v].first = g[v][0];
	}else{
		dfs(g[v][0]);
		color[v].first = color[g[v][0]].first;
	}
	if(g[v][1] < 0){
		color[v].second = g[v][1];
	}else{
		dfs(g[v][1]);
		color[v].second = color[g[v][1]].first;
	}
}

bool chk(int v){
	//cout << v << " " << color[v].first << " " << color[v].second << "\n";
	if(color[v].first == R && color[v].second == R) return 1;
	if(color[v].first == B && color[v].second == B) return 0;
	if(color[v].first == R && color[v].second == B) return chk(g[v][1]);
	return 1;
}

int FindWinner(int T, std::vector<int> l, std::vector<int> r){
	int n = l.size();
	for(int i=0; i<n; i++){
		g[i].push_back(l[i]);
		g[i].push_back(r[i]);
	}
	dfs(0);
	if(color[0].first == B){
		return 0;
	}
	
	return chk(0);
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...