Submission #150089

#TimeUsernameProblemLanguageResultExecution timeMemory
150089JeffreyHo (#200)Bulb Game (FXCUP4_bulb)C++17
0 / 100
2 ms376 KiB
#include "bulb.h" using namespace std; int l[300005], r[300005], c[300005], d[300005], e[300005], f[300005], o; int t[600005], z; int que(int l, int r) { int z = 890328; for (l += o, r += o; l < r; l >>= 1, r >>= 1) { if (l & 1) z = min(z, t[l++]); if (r & 1) z = min(z, t[--r]); } return z; } void dfs(int x) { d[x] = o; if (l[x] >= 0) c[l[x]] = c[x], dfs(l[x]); if (l[x] == -2) f[o++] = c[x]; if (r[x] >= 0) c[r[x]] = c[x] + 1, dfs(r[x]); if (r[x] == -2) f[o++] = c[x] + 1; e[x] = o; } void dfs2(int x) { if (que(0, d[x]) >= 2 && que(d[x], e[x]) >= 3 && que(e[x], o) >= 2) z = 1; if (l[x] >= 0) dfs2(l[x]); if (r[x] >= 0) dfs2(r[x]); } int FindWinner(int k, std::vector<int> L, std::vector<int> R) { int n = (int)L.size(); for (int i = 0; i < n; i++) l[i] = L[i], r[i] = R[i]; dfs(0); //for (int i = 0; i < n; i++) printf("%d %d %d\n", c[i], d[i], e[i]); for (int i = 0; i < o; i++) t[i + o] = f[i]; for (int i = o - 1; i; i--) t[i] = min(t[i << 1], t[i << 1 | 1]); //for (int i = 0; i < o + o; i++) printf("%d ", t[i]); //printf("%d\n", que(0, 2)); dfs2(0); return z; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...