# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877085 | 2023-11-22T20:33:11 Z | MilosMilutinovic | Toy Train (IOI17_train) | C++14 | 7 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<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] == 1) { 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> c; for (int i = 0; i < n; i++) { if (r[i] == 1 && !rem[i]) { c.push_back(i); } } 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<bool> in(n); for (int x : v) { in[x] = true; } vector<int> vec; for (int i = 0; i < n; i++) { if (!rem[i] && !in[i]) { vec.push_back(i); } } vector<int> bad = CalcB(vec); for (int x : bad) { rem[x] = true; } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 1276 KB | 3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 1628 KB | Output is correct |
2 | Correct | 5 ms | 1628 KB | Output is correct |
3 | Correct | 5 ms | 1628 KB | Output is correct |
4 | Incorrect | 6 ms | 1372 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 1368 KB | 3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 1368 KB | 3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 1276 KB | 3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |