Submission #149813

# Submission time Handle Problem Language Result Execution time Memory
149813 2019-09-01T07:12:40 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) Bulb Game (FXCUP4_bulb) C++17
0 / 100
9 ms 7544 KB
#include "bulb.h"
#include <vector>

using namespace std;

vector<int> L, R;

int n;
vector<int> ch[300001];
int dep[300001];
bool imp[300001];
int need[300001];
int all;

void dfs(int x) {
    while (ch[x].size() > 3) ch[x].pop_back();
    if (L[x] < 0) {
        if (L[x] == -1);
        else if (ch[x].size() > 2);
        else if (ch[x].size() == 2) {
            imp[ch[x][0]] = imp[ch[x][1]] = 1;
        }
        else if (ch[x].size() == 1) {
            ++need[x];
            ++all;
            if (dep[x] < n - 1) imp[ch[x][0]] = 1; 
        }
        else {
            throw 0;
        }
    }
    else {
        dep[L[x]] = dep[x] + 1;
        for (int i : ch[x]) ch[L[x]].push_back(i);
        dfs(L[x]);
        need[x] += need[L[x]];
    }
    ch[x].push_back(x);
    if (R[x] < 0) {
        if (L[x] == -1);
        else if (ch[x].size() > 2);
        else if (ch[x].size() == 2) {
            imp[ch[x][0]] = imp[ch[x][1]] = 1;
        }
        else if (ch[x].size() == 1) {
            ++need[x];
            ++all;
            if (dep[x] < n - 1) imp[ch[x][0]] = 1;
        }
        else {
            throw 0;
        }
    }
    else {
        dep[R[x]] = dep[x] + 1;
        for (int i : ch[x]) ch[R[x]].push_back(i);
        dfs(R[x]);
        need[x] += need[R[x]];
    }
}

int FindWinner(int T, vector<int> _L, vector<int> _R) {
    n = _L.size();
    L = _L;
    R = _R;
    try {
        dfs(0);
        for (int i = 0; i < n; ++i) {
            if (need[i] == all && !imp[i]) throw 1;
        }
        throw 0;
    } catch (int ret) {
        return ret;
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7388 KB Output is correct
2 Correct 9 ms 7444 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Incorrect 9 ms 7544 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 9 ms 7436 KB Output is correct
3 Correct 9 ms 7388 KB Output is correct
4 Correct 9 ms 7444 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Incorrect 9 ms 7544 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 9 ms 7436 KB Output is correct
3 Correct 9 ms 7388 KB Output is correct
4 Correct 9 ms 7444 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Incorrect 9 ms 7544 KB Output isn't correct
7 Halted 0 ms 0 KB -