Submission #150127

# Submission time Handle Problem Language Result Execution time Memory
150127 2019-09-01T07:46:11 Z TLEWA맞(#3625, H_Squad, sungjune222, str0ct) Bulb Game (FXCUP4_bulb) C++17
0 / 100
2 ms 376 KB
#include "bulb.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int dp[300010];     //(r, r)=1, (r, b)=2, (b, r)=3, (b, b)=4;
int n;
int winnable=-1;
vector<int> l, r;
void get_dp(int num)
{
    if(l[num]==-1&&r[num]==-1)dp[num]=1;
    if(l[num]==-1&&r[num]==-2)dp[num]=2;
    if(l[num]==-2&&r[num]==-1)dp[num]=3;
    if(l[num]==-2&&r[num]==-2)dp[num]=4;
    if(l[num]<0&&r[num]>=0){
        get_dp(r[num]);
        if(dp[r[num]]<=2&&l[num]==-1)dp[num]=1;
        if(dp[r[num]]<=2&&l[num]==-2)dp[num]=3;
        if(dp[r[num]]>=3&&l[num]==-1)dp[num]=2;
        if(dp[r[num]]>=3&&l[num]==-2)dp[num]=4;
    }
    if(r[num]<0&&l[num]>=0){
        get_dp(l[num]);
        if(dp[l[num]]<=2&&r[num]==-1)dp[num]=1;
        if(dp[l[num]]<=2&&r[num]==-2)dp[num]=2;
        if(dp[l[num]]>=3&&r[num]==-1)dp[num]=3;
        if(dp[l[num]]>=3&&r[num]==-2)dp[num]=4;
    }
    if(l[num]>=0&r[num]>=0){
        get_dp(r[num]);
        get_dp(l[num]);
        if(dp[l[num]]<=2&&dp[r[num]]<=2)dp[num]=1;
        if(dp[l[num]]<=2&&dp[r[num]]>=3)dp[num]=2;
        if(dp[l[num]]>=3&&dp[r[num]]<=2)dp[num]=3;
        if(dp[l[num]]>=3&&dp[r[num]]>=3)dp[num]=4;
    }
}
void dfs(int num)
{
    if(l[num]<0)return;
    if(dp[num]!=1){
        winnable=0;
        return;
    }
    if(r[num]>=0){
        if(dp[r[num]]==1){
            winnable=1;
            return;
        }
    }
    dfs(l[num]);
}
int FindWinner(int t, std::vector<int> L, std::vector<int> R){
	l=L;
	r=R;
	n = l.size();
	get_dp(0);
	dfs(0);
	return winnable==1;
}

Compilation message

bulb.cpp: In function 'void get_dp(int)':
bulb.cpp:34:14: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
     if(l[num]>=0&r[num]>=0){
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -