Submission #68946

#TimeUsernameProblemLanguageResultExecution timeMemory
68946aquablitz11Toy Train (IOI17_train)C++14
0 / 100
2084 ms112096 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; using pii = pair<int, int>; const int N = 5e3+10; int n, m; vector<int> G[N], R[N]; vector<int> A, C; bool can[N][N]; int cnt[N][N], need[N]; void dfs(int u, int p) { if (C[u] && p < n) return void(dfs(u, n)); if (p < 0) return; if (can[u][p]) return; can[u][p] = true; for (auto v : G[u]) dfs(v, p-1); } vector<int> who_wins(vector<int> AA, vector<int> CC, vector<int> U, vector<int> V) { swap(AA, A), swap(CC, C); // input n = A.size(); m = U.size(); for (int i = 0; i < m; ++i) { G[U[i]].push_back(V[i]); R[V[i]].push_back(U[i]); } // find reachable states for (int i = 0; i < n; ++i) { need[i] = A[i] ? (int)G[i].size() : 1; dfs(i, n); } // winning position vector<int> ans(n, 1); queue<pii> Q; for (int i = 0; i < n; ++i) if (can[i][0]) Q.emplace(i, 0); while (!Q.empty()) { int u = Q.front().first, p = Q.front().second; Q.pop(); if (p == n) ans[u] = 0; int pl = 1, pr = n; if (!C[u]) pl = pr = p+1; for (auto v : R[u]) { for (int np = pl; np <= pr && np <= n; ++np) { ++cnt[v][np]; if (can[v][n] && cnt[v][np] == need[v]) { can[v][np] = false; Q.emplace(v, np); } } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...