Submission #148865

#TimeUsernameProblemLanguageResultExecution timeMemory
148865본인 하지만 안 어림 ㅋㅋ (#200)Bulb Game (FXCUP4_bulb)C++17
100 / 100
109 ms23848 KiB
#include "bulb.h" using namespace std; int d[300003], D[300003]; int c[300003]; int b[300003]; void dfs1(int x, vector<int> &L) { d[x] = L[x]; D[x] = 1; if (d[x] >= 0) { dfs1(d[x], L); D[x] += D[d[x]]; d[x] = d[d[x]]; } } void dfs2(int x, vector<int> &L, vector<int> &R) { if (L[x] >= 0) dfs2(L[x], L, R); if (R[x] >= 0) dfs2(R[x], L, R); c[x] = R[x] == -2 || d[R[x]] == -2 || (L[x] >= 0 && c[L[x]] == -2) ? -2 : -1; b[x] = R[x] == -1 || d[R[x]] == -1 || (L[x] >= 0 && b[L[x]] == -1) ? -1 : -2; } int FindWinner(int T, std::vector<int> L, std::vector<int> R){ int i, j, k, t, N = L.size(); for (i = 0; i < N; i++) if (!d[i]) dfs1(i, L); if (d[0] == -2) return 0; dfs2(0, L, R); for (i = 0, j = 1; i >= 0; i = L[i], j++) { if (j == N || R[i] == -1 || (R[i] >= 0 && c[R[i]] == -1 && (d[R[i]] == -1 || j + D[R[i]] == N))) return 1; if (R[i] == -2 || R[i] >= 0 && d[R[i]] == -2) break; } t = D[0]; for (i = j = k = 0; i >= 0; i = L[i]) { if (R[i] == -2) return 0; if (R[i] >= 0) { if (d[R[i]] == -2 && b[R[i]] == -2) return 0; t += D[R[i]]; if (b[R[i]] == -1) k++; if (d[R[i]] != -1) j++; } } return j <= 1 && k + N - t >= 1; }

Compilation message (stderr)

bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:33:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (R[i] == -2 || R[i] >= 0 && d[R[i]] == -2) break;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...