# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
832334 |
2023-08-21T09:13:29 Z |
finn__ |
Toy Train (IOI17_train) |
C++17 |
|
9 ms |
2004 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
constexpr size_t N = 5000;
vector<int> g[N], rg[N], postorder, scc[N];
bitset<N> visited, is_charging, f;
int ind[N];
void postorder_dfs(int u)
{
visited[u] = 1;
for (auto const &v : g[u])
if (!visited[v])
postorder_dfs(v);
postorder.push_back(u);
}
void find_scc(int u, size_t s)
{
visited[u] = 1;
scc[s].push_back(u);
ind[u] = s;
for (auto const &v : rg[u])
if (!visited[v])
find_scc(v, s);
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
size_t const n = a.size(), m = u.size();
int subtask = 1;
for (size_t i = 0; i < m; ++i)
if (u[i] != v[i] && u[i] + 1 != v[i])
{
subtask = 3;
break;
}
vector<int> w(n);
if (subtask == 1)
{
vector<bool> has_edge(n), has_loop(n);
for (size_t i = 0; i < m; ++i)
{
if (u[i] == v[i])
has_loop[u[i]] = 1;
else
has_edge[u[i]] = 1;
}
for (size_t i = 0; i < n; ++i)
{
for (size_t j = i; j < n; ++j)
if (has_loop[j])
{
if (!(a[j] ^ r[j]))
{
w[i] = a[j];
break;
}
if (!has_edge[j])
{
w[i] = !a[j];
break;
}
}
}
return w;
}
for (size_t i = 0; i < n; ++i)
is_charging[i] = r[i];
for (size_t i = 0; i < m; ++i)
g[u[i]].push_back(v[i]), rg[v[i]].push_back(u[i]);
for (size_t i = 0; i < n; ++i)
if (!visited[i])
postorder_dfs(i);
visited.reset();
size_t s = 0;
for (auto it = postorder.rbegin(); it != postorder.rend(); ++it)
if (!visited[*it])
{
find_scc(*it, s++);
}
for (int &x : a)
if (!x)
{
subtask = 4;
break;
}
if (subtask == 3)
{
for (size_t i = 0; i < s; ++i)
{
bool has_charging_node = 0;
for (int u : scc[i])
has_charging_node |= r[u];
bool has_cycle = scc[i].size() > 1;
for (int u : scc[i])
for (int v : g[u])
has_cycle |= u == v;
if (has_cycle && has_charging_node)
{
f[i] = 1;
}
}
for (size_t i = s - 1; i < s; --i)
if (f[i])
{
for (auto const u : scc[i])
for (auto const &v : rg[u])
f[ind[v]] = 1;
}
for (size_t i = 0; i < n; ++i)
w[i] = f[ind[i]];
}
else
{
}
return w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
596 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 |
5 ms |
1876 KB |
Output is correct |
2 |
Correct |
5 ms |
1748 KB |
Output is correct |
3 |
Correct |
5 ms |
1748 KB |
Output is correct |
4 |
Correct |
7 ms |
1748 KB |
Output is correct |
5 |
Correct |
7 ms |
1832 KB |
Output is correct |
6 |
Correct |
9 ms |
1748 KB |
Output is correct |
7 |
Correct |
6 ms |
1748 KB |
Output is correct |
8 |
Correct |
6 ms |
1748 KB |
Output is correct |
9 |
Correct |
7 ms |
1748 KB |
Output is correct |
10 |
Correct |
7 ms |
1740 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
12 |
Correct |
6 ms |
1696 KB |
Output is correct |
13 |
Correct |
7 ms |
1876 KB |
Output is correct |
14 |
Correct |
7 ms |
1948 KB |
Output is correct |
15 |
Correct |
6 ms |
2004 KB |
Output is correct |
16 |
Correct |
7 ms |
1876 KB |
Output is correct |
17 |
Correct |
7 ms |
1956 KB |
Output is correct |
18 |
Correct |
4 ms |
1572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1492 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 |
6 ms |
1620 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 |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Incorrect |
0 ms |
596 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
13 |
Halted |
0 ms |
0 KB |
- |