답안 #149787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149787 2019-09-01T07:10:02 Z 욱방켜!! (twitch.tv/wookje)(#3584, kig9981, cheetose, jh05013) Bulb Game (FXCUP4_bulb) C++17
0 / 100
2 ms 380 KB
#include "bulb.h"
#include <bits/stdc++.h>

std::vector<int> L, R;
int dist[300000], mdist;

void dfs(int c, int v)
{
	mdist=std::max(mdist,v);
	if(L[c]>=0) {
		dist[L[c]]=dist[c]+1;
		dfs(L[c],v);
	}
	if(R[c]>=0) {
		dist[R[c]]=dist[c]+1;
		dfs(R[c],v+1);
	}
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int N = L.size(), c, n, t;
	std::vector<int> t1, t2;
	::L=L; ::R=R;
	for(c=0;c>=0;c=L[c]) {
		bool valid=false;
		for(n=R[c];n>=0;n=L[n]) {
			for(t=R[n];t>=0;t=L[t]);
			if(t==-1) valid=true;
		}
		if(valid) t2.push_back(c);
		if(n==-2) t1.push_back(c);
	}
	std::sort(t1.begin(),t1.end());
	std::sort(t2.begin(),t2.end());
	if(c==-2 || t1.size()>1 || t1.size()==1 && !binary_search(t2.begin(),t2.end(),t1[0])) return 0;
	dfs(0,0);
	if(t1.empty()) return mdist>1 || t2.size()>0;
	return 1;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:35:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  if(c==-2 || t1.size()>1 || t1.size()==1 && !binary_search(t2.begin(),t2.end(),t1[0])) return 0;
                             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulb.cpp:21:6: warning: unused variable 'N' [-Wunused-variable]
  int N = L.size(), c, n, t;
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -