답안 #150305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150305 2019-09-01T08:05:50 Z Dopatii(#3751, bogdan10bos, Gioto, Bodo171) Bulb Game (FXCUP4_bulb) C++17
0 / 100
3 ms 376 KB
#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

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);
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 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 -