# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289289 | 2020-09-02T14:13:19 Z | SamAnd | Toy Train (IOI17_train) | C++17 | 31 ms | 25976 KB |
#include "train.h" #include <bits/stdc++.h> using namespace std; #define m_p make_pair #define fi first #define se second #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) typedef long long ll; const int N = 5003; int n; vector<int> a, r; vector<int> g[N]; bool u[N][N]; vector<int> rg[N]; vector<int> solv1() { vector<int> ans(n); for (int i = n - 1; i >= 0; --i) { if (a[i]) { if (r[i]) { if (u[i][i]) { ans[i] = 1; } else { ans[i] = ans[i + 1]; } } else { if (u[i][i + 1]) { ans[i] = ans[i + 1]; } else { ans[i] = 0; } } } else { if (!r[i]) { if (u[i][i]) { ans[i] = 0; } else { ans[i] = ans[i + 1]; } } else { if (u[i][i + 1]) { ans[i] = ans[i + 1]; } else { ans[i] = 1; } } } } return ans; } int c[N]; vector<int> v; void dfs0(int x) { c[x] = 1; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (!c[h]) dfs0(h); } v.push_back(x); } int k; void dfs1(int x) { c[x] = k; for (int i = 0; i < rg[x].size(); ++i) { int h = rg[x][i]; if (!c[h]) dfs1(h); } } vector<int> xg[N]; int q[N]; void kond() { for (int x = 0; x < n; ++x) { if (!c[x]) dfs0(x); } reverse(all(v)); memset(c, 0, sizeof c); for (int i = 0; i < n; ++i) { int x = v[i]; if (!c[x]) { ++k; dfs1(x); } } for (int x = 0; x < n; ++x) { for (int i = 0; i < g[x].size(); ++i) { int y = g[x][i]; if (c[x] != c[y]) { xg[c[x]].push_back(c[y]); } else ++q[c[x]]; } } } int ans[N]; bool cc[N]; bool uu[N]; void dfs3(int x) { cc[x] = true; if (q[x] && uu[x]) ans[x] = 1; for (int i = 0; i < xg[x].size(); ++i) { int h = xg[x][i]; if (!cc[h]) dfs3(h); if (ans[h]) ans[x] = 1; } } vector<int> solv3() { kond(); for (int x = 0; x < n; ++x) { if (r[x]) uu[c[x]] = true; } for (int i = 1; i <= k; ++i) { if (!cc[i]) { dfs3(i); } } vector<int> ansv; for (int x = 0; x < n; ++x) { ansv.push_back(ans[c[x]]); } return ansv; } int c2[N]; void dfs2(int x) { c2[x] = 1; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (r[h]) continue; if (!c2[h]) dfs2(h); else if (c2[h] == 1) uu[c[x]] = true; } c2[x] = 2; } void dfs4(int x) { cc[x] = true; if (uu[x]) ans[x] = 0; for (int i = 0; i < xg[x].size(); ++i) { int h = xg[x][i]; if (!cc[h]) dfs4(h); if (ans[h] == 0) ans[x] = 0; } } vector<int> solv4() { kond(); for (int x = 0; x < n; ++x) { if (r[x]) continue; if (!c2[x]) dfs2(x); } for (int i = 1; i <= k; ++i) ans[i] = 1; for (int i = 1; i <= k; ++i) { if (!cc[i]) dfs4(i); } vector<int> ansv; for (int x = 0; x < n; ++x) { ansv.push_back(ans[c[x]]); } return ansv; } std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V) { a = A; r = R; n = sz(a); bool z1 = true; for (int i = 0; i < sz(U); ++i) { int x = U[i]; int y = V[i]; g[x].push_back(y); rg[y].push_back(x); u[x][y] = true; if (x != y && x + 1 != y) z1 = false; } bool z3 = true; bool z4 = true; for (int i = 0; i < n; ++i) { if (a[i]) { z4 = false; } else { z3 = false; } } if (z4) return solv4(); if (z3) return solv3(); if (z1) return solv1(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 21248 KB | Output is correct |
2 | Correct | 23 ms | 21248 KB | Output is correct |
3 | Correct | 17 ms | 21248 KB | Output is correct |
4 | Correct | 20 ms | 21248 KB | Output is correct |
5 | Correct | 18 ms | 21248 KB | Output is correct |
6 | Correct | 16 ms | 21248 KB | Output is correct |
7 | Correct | 17 ms | 21504 KB | Output is correct |
8 | Correct | 16 ms | 21504 KB | Output is correct |
9 | Correct | 16 ms | 21248 KB | Output is correct |
10 | Correct | 19 ms | 21248 KB | Output is correct |
11 | Correct | 15 ms | 21248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 768 KB | 3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 21376 KB | Output is correct |
2 | Correct | 20 ms | 22272 KB | Output is correct |
3 | Correct | 27 ms | 23168 KB | Output is correct |
4 | Correct | 24 ms | 25888 KB | Output is correct |
5 | Correct | 25 ms | 25728 KB | Output is correct |
6 | Correct | 26 ms | 25472 KB | Output is correct |
7 | Correct | 25 ms | 25080 KB | Output is correct |
8 | Correct | 24 ms | 24064 KB | Output is correct |
9 | Correct | 23 ms | 22776 KB | Output is correct |
10 | Correct | 31 ms | 24320 KB | Output is correct |
11 | Correct | 27 ms | 24056 KB | Output is correct |
12 | Correct | 24 ms | 25344 KB | Output is correct |
13 | Correct | 31 ms | 25592 KB | Output is correct |
14 | Correct | 24 ms | 25600 KB | Output is correct |
15 | Correct | 24 ms | 25600 KB | Output is correct |
16 | Correct | 28 ms | 25728 KB | Output is correct |
17 | Correct | 24 ms | 25856 KB | Output is correct |
18 | Correct | 19 ms | 24608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 24832 KB | Output is correct |
2 | Correct | 24 ms | 25464 KB | Output is correct |
3 | Correct | 27 ms | 25848 KB | Output is correct |
4 | Correct | 31 ms | 25080 KB | Output is correct |
5 | Correct | 24 ms | 24312 KB | Output is correct |
6 | Correct | 28 ms | 23808 KB | Output is correct |
7 | Correct | 23 ms | 24576 KB | Output is correct |
8 | Correct | 28 ms | 24320 KB | Output is correct |
9 | Correct | 24 ms | 25600 KB | Output is correct |
10 | Correct | 25 ms | 25848 KB | Output is correct |
11 | Correct | 25 ms | 25848 KB | Output is correct |
12 | Correct | 26 ms | 25976 KB | Output is correct |
13 | Correct | 27 ms | 25728 KB | Output is correct |
14 | Correct | 30 ms | 25464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 25344 KB | 3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 21248 KB | Output is correct |
2 | Correct | 23 ms | 21248 KB | Output is correct |
3 | Correct | 17 ms | 21248 KB | Output is correct |
4 | Correct | 20 ms | 21248 KB | Output is correct |
5 | Correct | 18 ms | 21248 KB | Output is correct |
6 | Correct | 16 ms | 21248 KB | Output is correct |
7 | Correct | 17 ms | 21504 KB | Output is correct |
8 | Correct | 16 ms | 21504 KB | Output is correct |
9 | Correct | 16 ms | 21248 KB | Output is correct |
10 | Correct | 19 ms | 21248 KB | Output is correct |
11 | Correct | 15 ms | 21248 KB | Output is correct |
12 | Incorrect | 1 ms | 768 KB | 3rd lines differ - on the 1st token, expected: '0', found: '1' |
13 | Halted | 0 ms | 0 KB | - |