Submission #150849

#TimeUsernameProblemLanguageResultExecution timeMemory
150849Powered By Zigui (#200)Bulb Game (FXCUP4_bulb)C++17
0 / 100
4 ms2680 KiB
#include "bulb.h" #include <algorithm> #include <string.h> using namespace std; const int BCOL = 300001; const int RCOL = 300002; int l[300003], r[300003], par[300003]; int go_left_chk[300003]; int chk_route_dp[300003]; int color[300003]; int go_left(int x) { int& ret = go_left_chk[x]; if(~ret) return ret; if(x == BCOL) return ret = 0; else if(x == RCOL) return ret = 1; return ret = go_left(l[x]); } int chk_route(int x) { int& ret = chk_route_dp[x]; if(~ret) return ret; if(x == BCOL) return ret = 0; else if(x == RCOL) return ret = 1; return ret = (chk_route(l[x]) && go_left(r[x])); } int chk_exception(int x) { if(x == BCOL || x == RCOL) { return 1; } return chk_exception(l[x]) && (r[x] == RCOL); } int FindWinner(int T, std::vector<int> L, std::vector<int> R){ memset(go_left_chk, -1, sizeof(go_left_chk)); memset(chk_route_dp, -1, sizeof(chk_route_dp)); int N = L.size(); for(int i=0;i<N;i++) { l[i] = (L[i] >= 0 ? L[i] : 300003 + L[i]); r[i] = (R[i] >= 0 ? R[i] : 300003 + R[i]); } if(!go_left(0)) return 0; if(N == 1) return 1; int cnt = 0; int pos = 0; while(pos != RCOL) { if(chk_route(r[pos])) { return 1; } if(!cnt && l[pos] >= BCOL && chk_exception(r[pos])) { return 1; } if(!go_left(r[pos])) { return 0; } if(r[pos] < BCOL) cnt++; pos = l[pos]; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...