제출 #45477

#제출 시각아이디문제언어결과실행 시간메모리
45477alenam0161장난감 기차 (IOI17_train)C++17
38 / 100
2068 ms7424 KiB
#include "train.h" #include <algorithm> #include <iostream> #include <cstdio> #include <unordered_map> #include <unordered_set> #include <queue> using namespace std; const int N = 5e3 + 7; int n, m; unordered_set<int> R; vector<int> g[N], g1[N]; vector<int> A; unordered_set<int> rev(const unordered_set<int> &fi){ auto cur = fi; cur.clear(); for (int i = 0; i < n; ++i){ if (fi.count(i) == 0)cur.insert(i); } return cur; } unordered_set<int> Fw(int w, const unordered_set<int> &fi){ unordered_set<int> cur = fi; queue<int> q; for (int x : fi) q.push(x); while (!q.empty()){ auto it = q.front(); q.pop(); for (auto to : g1[it]){ if (cur.count(to) == 1) continue; bool __b = all_of(g[to].begin(), g[to].end(), [&](int x){return cur.count(x) == 1; }); if (A[to] == w || __b) { cur.insert(to); q.push(to); } } } return cur; } unordered_set<int> merge(const unordered_set<int> &fi, const unordered_set<int> &se){ unordered_set<int> All; for (auto it : fi) if (se.count(it) == 1) All.insert(it); return All; } void pr(const unordered_set<int> &st){ for (const auto &it : st){ cout << it << " "; } cout << endl; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { ::n = a.size(); ::A = a; ::m = u.size(); vector<int> res; for (int i = 0; i < n; ++i) if (r[i] == 1) R.insert(i); for (int i = 0; i < m; ++i){ g[u[i]].push_back(v[i]); g1[v[i]].push_back(u[i]); } while (true){ auto R_ex = Fw(1, R); auto X = rev(R_ex); auto X_ex = Fw(0, X); unordered_set<int> M = merge(R, X_ex); for (auto it : M) R.erase(it); if (M.size() == 0){ auto ans = vector<int>(n, 1); for (const auto &it : X_ex) ans[it] = 0; return ans; } } return res; }
#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...