답안 #147721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147721 2019-08-30T13:30:52 Z imsifile Bulb Game (FXCUP4_bulb) C++17
컴파일 오류
0 ms 0 KB
#include "bulb.h"
using namespace std;

int N, dlr[303030][2], dcn, par[303030], sw[303030], qsc, cha, ch[2], valid=-1, lose[303030];
vector<int> L, R;

int lca(int a, int b){
	if(a==-1) return b;
	if(a==-2) return a;
	while(a>=0){
		if(dlr[a][0] <= dlr[b][0] && dlr[b][0] <= dlr[a][1]) break;
		a=par[a];
	}
	return a;
}

void pre(int ix){
	if(ix<0) return;
	dlr[ix][0]=dcn++;
	pre(L[ix]), pre(R[ix]);
	dlr[ix][1]=dcn-1;
}

void dfs(int pv, int ix){
	if(ix==-1) return;
	if(ix==-2){
		if(cha==0) valid=-2;
		if(cha==1 && qsc) valid=lca(valid,pv), lose[ch[0]]=1;
		if(cha==2) lose[ch[0]]=lose[ch[1]]=1;
		return;
	}
	par[ix]=pv;
	sw[ix]=0, qsc--;
	dfs(ix, L[ix]);
	if(cha<2) ch[cha]=ix;
	sw[ix]=1, cha++;
	dfs(ix, R[ix]);
	sw[ix]=2, cha--, qsc++;
}

int FindWinner(int N_, int T, std::vector<int> L_, std::vector<int> R_){
	N=N_, L=L_, R=R_;
	for(int i=0; i<N; i++) sw[i]=2; qsc=N;
	pre(0);
	dfs(-1, 0);
	if(valid==-2) return 0;
	if(valid==-1){
		for(int i=0; i<N; i++){
			if(!lose[i]) return 1;
		}
		return 0;
	}
	for(int i=valid; i>=0; i=par[i]){
		if(!lose[i]) return 1;
	}
	return 0;
}

Compilation message

bulb.cpp: In function 'int FindWinner(int, int, std::vector<int>, std::vector<int>)':
bulb.cpp:43:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int i=0; i<N; i++) sw[i]=2; qsc=N;
  ^~~
bulb.cpp:43:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int i=0; i<N; i++) sw[i]=2; qsc=N;
                                  ^~~
/tmp/cclif1wp.o: In function `main':
grader.cpp:(.text.startup+0x159): undefined reference to `FindWinner(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status