답안 #211693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211693 2020-03-21T01:33:19 Z thebes Bulb Game (FXCUP4_bulb) C++17
100 / 100
99 ms 16120 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,int b){
    if(n<0) return;
    solve(ed[n].first,b);
    solve(ed[n].second,0);
    w[n][0]=ed[n].first<0?ed[n].first:w[ed[n].first][0];
    if(b){
        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);
            if(w[n][0]==-1) w[n][1]|=w[ed[n].second][1];
        }
        else if(ed[n].second==-1) w[n][1]=1;
    }
    else 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,1);
        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&&(f4==f2));
}
# 결과 실행 시간 메모리 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 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 97 ms 13048 KB Output is correct
28 Correct 91 ms 12920 KB Output is correct
29 Correct 92 ms 12792 KB Output is correct
30 Correct 98 ms 16120 KB Output is correct
31 Correct 89 ms 16036 KB Output is correct
32 Correct 93 ms 12868 KB Output is correct
33 Correct 98 ms 12884 KB Output is correct
34 Correct 96 ms 12836 KB Output is correct
35 Correct 90 ms 12792 KB Output is correct
36 Correct 90 ms 12920 KB Output is correct
37 Correct 93 ms 12792 KB Output is correct
38 Correct 91 ms 12836 KB Output is correct
39 Correct 95 ms 12920 KB Output is correct
40 Correct 92 ms 12792 KB Output is correct
41 Correct 91 ms 12836 KB Output is correct
42 Correct 93 ms 12768 KB Output is correct
43 Correct 99 ms 12792 KB Output is correct
44 Correct 90 ms 12792 KB Output is correct
45 Correct 90 ms 12792 KB Output is correct
46 Correct 99 ms 13048 KB Output is correct
47 Correct 99 ms 14840 KB Output is correct
48 Correct 99 ms 14920 KB Output is correct
49 Correct 97 ms 14712 KB Output is correct
50 Correct 97 ms 14712 KB Output is correct