Submission #150239

# Submission time Handle Problem Language Result Execution time Memory
150239 2019-09-01T07:57:44 Z Dopatii(#3751, bogdan10bos, Gioto, Bodo171) Bulb Game (FXCUP4_bulb) C++17
0 / 100
2 ms 380 KB
#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;

int wL[300005], wR[300005];
int TL[300005], TR[300005];
int l[300005], r[300005];
bool dfs(int nod, bool s){
    if(nod == -1 && s == 1) return 1;
    if(nod < 0) return 0;

    if(s == 0){
        bool ok1 = dfs(l[nod], 0);
        bool ok2 = dfs(r[nod], 1);
        return ok1 | ok2;
    }
    else{
        if(wL[nod] == -2 || wR[nod] == -2) return 0;
        if(nod == -2) return 0;
        return dfs(l[nod], 1);
    }
}

int FindWinner(int T, std::vector<int> L, std::vector<int> R){
	int N = L.size();
    for(int i = 0; i < N ; ++i) l[i] = L[i], r[i] = R[i];
	for(int i = 0; i < N ; ++i) TL[i] = TR[i] = -1;

    for(int i = 0; i < N ; ++i)
        if(L[i] >= 0) TL[L[i]] = i;

    for(int i = 0; i < N ; ++i)
        if(R[i] >= 0) TR[R[i]] = i;

    for(int i = 0; i < N ; ++i){
        if(L[i] >= 0) continue ;

        int nod = i;
        while(nod >= 0){
            wL[nod] = L[nod];
            nod = TL[nod];
        }
    }
    for(int i = 0; i < N ; ++i){
        if(R[i] >= 0) continue ;

        int nod = i;
        while(nod >= 0){
            wR[TR[nod]] = wL[nod];
            nod = TR[nod];
        }
    }

    if(wL[0] == -2) return 0;

    bool check = dfs(0, 0);

    if(!check) return 0;

    int nod = 0, nr = 0;
    while(nod >= 0){
        if(wR[nod] == -2) ++nr;
        nod = L[nod];
    }

    if(nr > 1) return 0;

	return 1;
}







# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -