이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |