Submission #68321

#TimeUsernameProblemLanguageResultExecution timeMemory
68321aquablitz11Toy Train (IOI17_train)C++14
15 / 100
2078 ms115672 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; using pii = pair<int, int>; const int N = 5e3+10; int n, m; int deg[N]; vector<int> R[N]; bool used[N*N]; int cnt[N*N]; vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V) { // input n = A.size(); m = U.size(); for (int i = 0; i < m; ++i) { ++deg[U[i]]; R[V[i]].push_back(U[i]); } // winning position for B queue<int> Q; for (int i = 0; i < n; ++i) { int vali = i*(n+1); used[vali] = true; Q.push(i*(n+1)+0); } vector<int> ans(n, 1); while (!Q.empty()) { int valu = Q.front(); int u = valu/(n+1), p = valu%(n+1); Q.pop(); if (p == n) ans[u] = 0; if (!C[u] && p+1 <= n) for (auto v : R[u]) { int np = p+1; if (C[v] && np != n) continue; int valv = v*(n+1)+np; ++cnt[valv]; if (cnt[valv] == (A[v] ? (int)deg[v] : 1) && !used[valv]) { used[valv] = true; Q.push(valv); } } if (C[u] && p == n) for (auto v : R[u]) { if (C[v]) { int np = n; int valv = v*(n+1)+np; ++cnt[valv]; if (cnt[valv] == (A[v] ? (int)deg[v] : 1) && !used[valv]) { used[valv] = true; Q.push(valv); } } else for (int np = 1; np <= n; ++np) { int valv = v*(n+1)+np; ++cnt[valv]; if (cnt[valv] == (A[v] ? (int)deg[v] : 1) && !used[valv]) { used[valv] = true; Q.push(valv); } } } } 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...