# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877079 | 2023-11-22T20:27:35 Z | MilosMilutinovic | Toy Train (IOI17_train) | C++14 | 2000 ms | 1628 KB |
#include "train.h" #include <bits/stdc++.h> using namespace std; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { int n = (int) a.size(); int m = (int) u.size(); vector<vector<int>> g(n); vector<vector<int>> t(n); for (int i = 0; i < m; i++) { g[u[i]].push_back(v[i]); t[v[i]].push_back(u[i]); } vector<int> c; for (int i = 0; i < n; i++) { if (r[i] == 1) { c.push_back(i); } } vector<bool> rem(n); auto CalcA = [&](vector<int> f) { vector<int> que = f; vector<int> deg(n); for (int i = 0; i < n; i++) { if (rem[i]) { continue; } if (a[i] == 0) { deg[i] = (int) g[i].size(); } else { deg[i] = 1; } } for (int x : que) { deg[x] = 0; } for (int b = 0; b < (int) que.size(); b++) { int x = que[b]; for (int y : t[x]) { if (deg[y] <= 0) { continue; } deg[y] -= 1; if (deg[y] == 0) { que.push_back(y); } } } return que; }; auto CalcB = [&](vector<int> f) { vector<int> que = f; vector<int> deg(n); for (int i = 0; i < n; i++) { if (rem[i]) { continue; } if (a[i] == 1) { deg[i] = 1; } else { deg[i] = (int) g[i].size(); } } for (int x : que) { deg[x] = 0; } for (int b = 0; b < (int) que.size(); b++) { int x = que[b]; for (int y : t[x]) { if (deg[y] <= 0) { continue; } deg[y] -= 1; if (deg[y] == 0) { que.push_back(y); } } } return que; }; vector<int> ans(n); while (true) { vector<int> v = CalcA(c); int cnt = 0; for (int i = 0; i < n; i++) { if (!rem[i]) { cnt += 1; } } if (v.size() == cnt) { for (int x : v) { ans[x] = 1; } break; } vector<int> bad = CalcB(v); for (int x : bad) { rem[x] = true; } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2051 ms | 1372 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2029 ms | 344 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2066 ms | 1624 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2077 ms | 1624 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2029 ms | 1628 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2051 ms | 1372 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |