Submission #150534

#TimeUsernameProblemLanguageResultExecution timeMemory
150534=SUM(D1:D9) (#200)Bulb Game (FXCUP4_bulb)C++17
100 / 100
89 ms8192 KiB
#include "bulb.h"

std::vector<int> left,right;
std::pair<int,int> func(int k)
{
	int pivot;
	int C = 1;
	for(pivot = k; pivot>=0; pivot = left[pivot])
	{
		int p = right[pivot];
		while(p>=0) p = left[p];
		if(p==-2) C = 0;
	}
	if(pivot==-2) return std::make_pair(0,C);
	else return std::make_pair(1,C);
	
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int N = L.size();
	left = L, right = R;
	
	int pivot = 0;
	while(pivot>=0) pivot = L[pivot];
	if(pivot==-2) return 0;
	
	pivot = 0;
	while(pivot>=0)
	{
		std::pair<int,int> P = func(R[pivot]);
		if(P.second==1) return 1;
		if(P.first==1) pivot = L[pivot];
		else return 0;
	}
	return 1;
}

Compilation message (stderr)

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:20:6: warning: unused variable 'N' [-Wunused-variable]
  int N = L.size();
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...