답안 #211691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211691 2020-03-21T01:23:49 Z thebes Bulb Game (FXCUP4_bulb) C++17
0 / 100
5 ms 384 KB
#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back

const int MN = 3e5+5;
int N, i, res[MN], w[MN][2], vs[MN], f, f2, f3, f4;
pii ed[MN];

int acc(int n){
    if(n<0) return 0;
    if(res[n]) return res[n];
    res[n]=ed[n].first<0?ed[n].first:acc(ed[n].first);
    return res[n];
}

void solve(int n){
    if(n<0) return;
    if(vs[n]) return;
    vs[n] = 1;
    solve(ed[n].first);
    solve(ed[n].second);
    w[n][0]=ed[n].first<0?ed[n].first:w[ed[n].first][0];
    if(ed[n].first>=0) w[n][1]|=w[ed[n].first][1];
    if(ed[n].second>=0) w[n][1]|=(w[ed[n].second][0]==-1)||w[ed[n].second][1];
    else if(ed[n].second==-1) w[n][1]=1;
}

int ok(int n,int hm){
    while(n>=0){
        if(ed[n].second==-2||acc(ed[n].second)==-2) return 0;
        n=ed[n].first; hm++;
    }
    if(hm==N) return 1;
    else return (n==-1);
}

int FindWinner(int T,vi L,vi R){
    N = L.size();
    int cur = 0;
    for(i=0;i<N;i++) ed[i]={L[i],R[i]};
    int cnt = 0;
    while(cur>=0){
        solve(ed[cur].second);
        cnt ++;
        if(!f2){
            if(ok(ed[cur].second,cnt)) f=1;
        }
        if(ed[cur].second>=0){
            if(w[ed[cur].second][1]) f3=1;
            if(w[ed[cur].second][1]&&(ed[cur].second==-2||acc(ed[cur].second)==-2))
                f4=1;
        }
        if(ed[cur].second==-2||acc(ed[cur].second)==-2) f2++;
        cur = ed[cur].first;
    }
    if(acc(0)==-2) return 0;
    else return f|(f3&&(f2<=1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -