Submission #150305

#TimeUsernameProblemLanguageResultExecution timeMemory
150305Dopatii (#200)Bulb Game (FXCUP4_bulb)C++17
0 / 100
3 ms376 KiB
#include <bits/stdc++.h>
#include "bulb.h"

using namespace std;

int N;
vector<int> l, r, whr, good, down;

void DFS(int nod)
{
	if(nod < 0)	return;
	DFS(l[nod]);
	DFS(r[nod]);

	if(l[nod] < 0)	whr[nod] = l[nod];
	else	whr[nod] = whr[ l[nod] ];

	good[nod] = (whr[nod] == -1);
	if(r[nod] < 0)	good[nod] &= (r[nod] == -1);
	else	good[nod] &= (whr[ r[nod] ] == -1);

	if(l[nod] < 0)	down[nod] = good[nod];
	else	down[nod] = good[nod] & down[ l[nod] ];
}

int DFS2(int nod)
{
	if(r[nod] > 0 && down[ r[nod] ])	return 1;

	if(l[nod] < 0)
	{
		if(good[nod])	return 1;
		return 0;
	}

	if(good[nod])	return DFS2(l[nod]);
	return 0;
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R)
{
	N = L.size();
	l = L, r = R;
	whr.resize(N); good.resize(N); down.resize(N);
	DFS(0);
	if(whr[0] == -2)	return 0;
	int ans = DFS2(0);
	return 0;
}

Compilation message (stderr)

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:47:6: warning: unused variable 'ans' [-Wunused-variable]
  int ans = DFS2(0);
      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...