Submission #229276

#TimeUsernameProblemLanguageResultExecution timeMemory
229276534351Bulb Game (FXCUP4_bulb)C++17
0 / 100
5 ms512 KiB
#include "bulb.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; const int MAXN = 300013; int N; pii child[MAXN]; bitset<MAXN> bad, onpath; bool flag; //are offpath banned? vi path; //-1 if it's red (so a result of 1 / a win) void dfs(int u, vi dif) { if (child[u].fi < 0) { if (child[u].fi == -2) { // cerr << "uhoh " << u << endl; if (SZ(dif) == 2) { //u and v are not allowed. bad[dif[0]] = true; bad[dif[1]] = true; } else if (SZ(dif) == 1) { bad[dif[0]] = true; flag = true; } else { assert(false); } } } else { dfs(child[u].fi, dif); } if (SZ(dif) < 2) { if (child[u].se < 0) { if (SZ(dif) == 1) { bad[u] = true; bad[dif[0]] = true; } else if (dif.empty()) { bad[u] = true; flag = true; } else { assert(false); } } else { dif.PB(u); dfs(child[u].se, dif); } } } int FindWinner(int T, std::vector<int> L, std::vector<int> R) { N = SZ(L); FOR(i, 0, N) { child[i] = {L[i], R[i]}; } path.PB(0); while(path.back() >= 0) { path.PB(child[path.back()].fi); } if (path.back() == -2) { return 0; } path.pop_back(); for (int u : path) { onpath[u] = true; } dfs(0, vi(0)); // cerr << "flag ? " << flag << endl; FOR(u, 0, N) { if (onpath[u]) { if (!bad[u]) return 1; } else { if (!bad[u] && !flag) return 1; } } return 0; //for you to be able to win with switching x: //if x is not the direct left path, eh it's kinda pointless then. //T doesn't matter?? you literally just like, try it to see if there's a move 0 can choose //check if there's a node you can toggle such that everybody remains safe. }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...