# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289282 | 2020-09-02T14:08:55 Z | SamAnd | Toy Train (IOI17_train) | C++17 | 25 ms | 25856 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; } void dfs2(int x) { cc[x] = true; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (r[h]) continue; if (!cc[h]) dfs2(h); else uu[c[x]] = true; } } 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 (!cc[x]) dfs2(x); } memset(cc, false, sizeof cc); 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 (z3) return solv3(); if (z1) return solv1(); if (z4) return solv4(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 21248 KB | Output is correct |
2 | Correct | 17 ms | 21248 KB | Output is correct |
3 | Correct | 15 ms | 21248 KB | Output is correct |
4 | Correct | 16 ms | 21248 KB | Output is correct |
5 | Correct | 16 ms | 21248 KB | Output is correct |
6 | Correct | 15 ms | 21248 KB | Output is correct |
7 | Correct | 16 ms | 21248 KB | Output is correct |
8 | Correct | 16 ms | 21504 KB | Output is correct |
9 | Correct | 16 ms | 21248 KB | Output is correct |
10 | Correct | 16 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 2nd token, expected: '1', found: '0' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21288 KB | Output is correct |
2 | Correct | 22 ms | 22272 KB | Output is correct |
3 | Correct | 21 ms | 23168 KB | Output is correct |
4 | Correct | 25 ms | 25856 KB | Output is correct |
5 | Correct | 25 ms | 25728 KB | Output is correct |
6 | Correct | 24 ms | 25472 KB | Output is correct |
7 | Correct | 25 ms | 25088 KB | Output is correct |
8 | Correct | 23 ms | 23936 KB | Output is correct |
9 | Correct | 22 ms | 22784 KB | Output is correct |
10 | Correct | 24 ms | 24188 KB | Output is correct |
11 | Correct | 23 ms | 23928 KB | Output is correct |
12 | Correct | 24 ms | 25472 KB | Output is correct |
13 | Correct | 25 ms | 25600 KB | Output is correct |
14 | Correct | 24 ms | 25600 KB | Output is correct |
15 | Correct | 25 ms | 25728 KB | Output is correct |
16 | Correct | 24 ms | 25600 KB | Output is correct |
17 | Correct | 24 ms | 25728 KB | Output is correct |
18 | Correct | 19 ms | 24704 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 24832 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 | Incorrect | 25 ms | 25464 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 | 16 ms | 21248 KB | Output is correct |
2 | Correct | 17 ms | 21248 KB | Output is correct |
3 | Correct | 15 ms | 21248 KB | Output is correct |
4 | Correct | 16 ms | 21248 KB | Output is correct |
5 | Correct | 16 ms | 21248 KB | Output is correct |
6 | Correct | 15 ms | 21248 KB | Output is correct |
7 | Correct | 16 ms | 21248 KB | Output is correct |
8 | Correct | 16 ms | 21504 KB | Output is correct |
9 | Correct | 16 ms | 21248 KB | Output is correct |
10 | Correct | 16 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 2nd token, expected: '1', found: '0' |
13 | Halted | 0 ms | 0 KB | - |