# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57234 |
2018-07-14T09:58:10 Z |
Crown |
Toy Train (IOI17_train) |
C++14 |
|
2000 ms |
16412 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 5005;
int out[maxn];
int sz[maxn];
int inq[maxn];
int proc[maxn];
int Who_wins[maxn];
bool vis[maxn];
vector<int> A;
vector<int> R;
vector<int> adj[maxn];
vector<int> rev[maxn];
vector<int> bic[maxn];
int n, m;
vector<int> f(int is_a, vector<int> &all, vector<int> &s)
{
for(auto u : all)
{
inq[u] = 0;
out[u] = sz[u];
}
queue<int> q;
for(auto u : s)
{
inq[u] = true;
q.push(u);
}
vector<int> res = s;
while(!q.empty())
{
int u = q.front(); q.pop();
for(auto v : rev[u])
{
if(inq[v] || proc[v]) continue;
out[v]--;
if(A[v] == is_a)
{
inq[v] = true;
res.pb(v);
q.push(v);
}
else if(out[v] == 0)
{
inq[v] = true;
res.pb(v);
q.push(v);
}
}
}
return res;
}
void dfs(int u, vector<int> &all, vector<int> &charge)
{
all.pb(u);
if(R[u]) charge.pb(u);
for(auto v : bic[u])
if(!vis[v] && !proc[v])
{
vis[v] = true;
dfs(v, all, charge);
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> _U, vector<int> _V)
{
A = a; R = r;
n = a.size(), m = _U.size();
for(int i = 0; i< m; i++)
{
int u = _U[i], v = _V[i];
adj[u].pb(v); rev[v].pb(u);
bic[u].pb(v); bic[v].pb(u);
}
for(int i = 0; i< n; i++) sz[i] = adj[i].size();
queue< pair<vector<int>, vector<int> > > Q;
for(int i = 0; i< n; i++)
{
if(vis[i]) continue;
vis[i] = true;
vector<int> all, charge;
dfs(i, all, charge);
Q.push(make_pair(all, charge));
}
while(!Q.empty())
{
vector<int> all = Q.front().X, charge = Q.front().Y; Q.pop();
// for(auto u : all) printf("%d ", u); printf("\n");
// for(auto u : charge) printf("c%d ", u); printf("\n");
vector<int> f_a = f(1, all, charge);
vector<int> x;
sort(f_a.begin(), f_a.end());
for(auto u : all)
{
if(!binary_search(f_a.begin(), f_a.end(), u)) x.pb(u);
}
if(x.empty())
{
for(auto u : all) proc[u] = true;
for(auto u : all) Who_wins[u] = true;
for(auto u : all) for(auto v : rev[u]) sz[v]--;
continue;
}
vector<int> f_b = f(0, all, x);
for(auto u : f_b)
{
proc[u] = 1;
for(auto v : rev[u]) sz[v]--;
}
for(auto u : all) vis[u] = false;
for(auto u : all)
{
if(vis[u] || proc[u]) continue;
vis[u] = true;
vector<int> All, Charge;
dfs(u, All, Charge);
//for(auto u : All) printf("**%d ", u); printf("\n");
//for(auto u : Charge) printf("***%d ", u); printf("\n");
Q.push(make_pair(All, Charge));
}
}
vector<int> res(n);
for(int i = 0; i< n; i++) res[i] = Who_wins[i];
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1912 KB |
Output is correct |
2 |
Correct |
17 ms |
1976 KB |
Output is correct |
3 |
Correct |
13 ms |
2000 KB |
Output is correct |
4 |
Correct |
15 ms |
2176 KB |
Output is correct |
5 |
Correct |
11 ms |
2252 KB |
Output is correct |
6 |
Correct |
11 ms |
2300 KB |
Output is correct |
7 |
Correct |
14 ms |
2508 KB |
Output is correct |
8 |
Correct |
14 ms |
2508 KB |
Output is correct |
9 |
Correct |
11 ms |
2584 KB |
Output is correct |
10 |
Correct |
12 ms |
2712 KB |
Output is correct |
11 |
Correct |
14 ms |
3048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3048 KB |
Output is correct |
2 |
Correct |
3 ms |
3048 KB |
Output is correct |
3 |
Correct |
3 ms |
3048 KB |
Output is correct |
4 |
Correct |
3 ms |
3048 KB |
Output is correct |
5 |
Correct |
3 ms |
3048 KB |
Output is correct |
6 |
Correct |
3 ms |
3048 KB |
Output is correct |
7 |
Correct |
4 ms |
3048 KB |
Output is correct |
8 |
Correct |
3 ms |
3048 KB |
Output is correct |
9 |
Correct |
4 ms |
3048 KB |
Output is correct |
10 |
Correct |
2 ms |
3048 KB |
Output is correct |
11 |
Correct |
3 ms |
3048 KB |
Output is correct |
12 |
Correct |
4 ms |
3048 KB |
Output is correct |
13 |
Correct |
3 ms |
3048 KB |
Output is correct |
14 |
Correct |
3 ms |
3048 KB |
Output is correct |
15 |
Correct |
3 ms |
3048 KB |
Output is correct |
16 |
Correct |
3 ms |
3048 KB |
Output is correct |
17 |
Correct |
3 ms |
3048 KB |
Output is correct |
18 |
Correct |
3 ms |
3048 KB |
Output is correct |
19 |
Correct |
3 ms |
3048 KB |
Output is correct |
20 |
Correct |
3 ms |
3048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
3996 KB |
Output is correct |
2 |
Correct |
896 ms |
4184 KB |
Output is correct |
3 |
Correct |
1050 ms |
4380 KB |
Output is correct |
4 |
Correct |
21 ms |
4464 KB |
Output is correct |
5 |
Correct |
23 ms |
4664 KB |
Output is correct |
6 |
Correct |
26 ms |
4872 KB |
Output is correct |
7 |
Correct |
18 ms |
4952 KB |
Output is correct |
8 |
Correct |
22 ms |
5136 KB |
Output is correct |
9 |
Correct |
15 ms |
5240 KB |
Output is correct |
10 |
Correct |
25 ms |
5560 KB |
Output is correct |
11 |
Correct |
18 ms |
5628 KB |
Output is correct |
12 |
Correct |
15 ms |
5840 KB |
Output is correct |
13 |
Correct |
17 ms |
6260 KB |
Output is correct |
14 |
Correct |
22 ms |
6468 KB |
Output is correct |
15 |
Correct |
18 ms |
6676 KB |
Output is correct |
16 |
Correct |
19 ms |
6884 KB |
Output is correct |
17 |
Correct |
21 ms |
7096 KB |
Output is correct |
18 |
Correct |
1679 ms |
7096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
7156 KB |
Output is correct |
2 |
Correct |
18 ms |
7316 KB |
Output is correct |
3 |
Correct |
20 ms |
7624 KB |
Output is correct |
4 |
Correct |
24 ms |
7832 KB |
Output is correct |
5 |
Correct |
30 ms |
8040 KB |
Output is correct |
6 |
Correct |
21 ms |
8244 KB |
Output is correct |
7 |
Correct |
22 ms |
8444 KB |
Output is correct |
8 |
Correct |
21 ms |
8592 KB |
Output is correct |
9 |
Correct |
19 ms |
8696 KB |
Output is correct |
10 |
Correct |
23 ms |
9152 KB |
Output is correct |
11 |
Correct |
21 ms |
9360 KB |
Output is correct |
12 |
Correct |
29 ms |
9568 KB |
Output is correct |
13 |
Correct |
21 ms |
9776 KB |
Output is correct |
14 |
Correct |
29 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
10172 KB |
Output is correct |
2 |
Correct |
24 ms |
10372 KB |
Output is correct |
3 |
Correct |
28 ms |
10660 KB |
Output is correct |
4 |
Correct |
27 ms |
10660 KB |
Output is correct |
5 |
Correct |
5 ms |
10660 KB |
Output is correct |
6 |
Correct |
13 ms |
10660 KB |
Output is correct |
7 |
Correct |
14 ms |
10660 KB |
Output is correct |
8 |
Correct |
15 ms |
10660 KB |
Output is correct |
9 |
Correct |
13 ms |
10660 KB |
Output is correct |
10 |
Correct |
5 ms |
10660 KB |
Output is correct |
11 |
Correct |
14 ms |
10660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1912 KB |
Output is correct |
2 |
Correct |
17 ms |
1976 KB |
Output is correct |
3 |
Correct |
13 ms |
2000 KB |
Output is correct |
4 |
Correct |
15 ms |
2176 KB |
Output is correct |
5 |
Correct |
11 ms |
2252 KB |
Output is correct |
6 |
Correct |
11 ms |
2300 KB |
Output is correct |
7 |
Correct |
14 ms |
2508 KB |
Output is correct |
8 |
Correct |
14 ms |
2508 KB |
Output is correct |
9 |
Correct |
11 ms |
2584 KB |
Output is correct |
10 |
Correct |
12 ms |
2712 KB |
Output is correct |
11 |
Correct |
14 ms |
3048 KB |
Output is correct |
12 |
Correct |
3 ms |
3048 KB |
Output is correct |
13 |
Correct |
3 ms |
3048 KB |
Output is correct |
14 |
Correct |
3 ms |
3048 KB |
Output is correct |
15 |
Correct |
3 ms |
3048 KB |
Output is correct |
16 |
Correct |
3 ms |
3048 KB |
Output is correct |
17 |
Correct |
3 ms |
3048 KB |
Output is correct |
18 |
Correct |
4 ms |
3048 KB |
Output is correct |
19 |
Correct |
3 ms |
3048 KB |
Output is correct |
20 |
Correct |
4 ms |
3048 KB |
Output is correct |
21 |
Correct |
2 ms |
3048 KB |
Output is correct |
22 |
Correct |
3 ms |
3048 KB |
Output is correct |
23 |
Correct |
4 ms |
3048 KB |
Output is correct |
24 |
Correct |
3 ms |
3048 KB |
Output is correct |
25 |
Correct |
3 ms |
3048 KB |
Output is correct |
26 |
Correct |
3 ms |
3048 KB |
Output is correct |
27 |
Correct |
3 ms |
3048 KB |
Output is correct |
28 |
Correct |
3 ms |
3048 KB |
Output is correct |
29 |
Correct |
3 ms |
3048 KB |
Output is correct |
30 |
Correct |
3 ms |
3048 KB |
Output is correct |
31 |
Correct |
3 ms |
3048 KB |
Output is correct |
32 |
Correct |
602 ms |
3996 KB |
Output is correct |
33 |
Correct |
896 ms |
4184 KB |
Output is correct |
34 |
Correct |
1050 ms |
4380 KB |
Output is correct |
35 |
Correct |
21 ms |
4464 KB |
Output is correct |
36 |
Correct |
23 ms |
4664 KB |
Output is correct |
37 |
Correct |
26 ms |
4872 KB |
Output is correct |
38 |
Correct |
18 ms |
4952 KB |
Output is correct |
39 |
Correct |
22 ms |
5136 KB |
Output is correct |
40 |
Correct |
15 ms |
5240 KB |
Output is correct |
41 |
Correct |
25 ms |
5560 KB |
Output is correct |
42 |
Correct |
18 ms |
5628 KB |
Output is correct |
43 |
Correct |
15 ms |
5840 KB |
Output is correct |
44 |
Correct |
17 ms |
6260 KB |
Output is correct |
45 |
Correct |
22 ms |
6468 KB |
Output is correct |
46 |
Correct |
18 ms |
6676 KB |
Output is correct |
47 |
Correct |
19 ms |
6884 KB |
Output is correct |
48 |
Correct |
21 ms |
7096 KB |
Output is correct |
49 |
Correct |
1679 ms |
7096 KB |
Output is correct |
50 |
Correct |
21 ms |
7156 KB |
Output is correct |
51 |
Correct |
18 ms |
7316 KB |
Output is correct |
52 |
Correct |
20 ms |
7624 KB |
Output is correct |
53 |
Correct |
24 ms |
7832 KB |
Output is correct |
54 |
Correct |
30 ms |
8040 KB |
Output is correct |
55 |
Correct |
21 ms |
8244 KB |
Output is correct |
56 |
Correct |
22 ms |
8444 KB |
Output is correct |
57 |
Correct |
21 ms |
8592 KB |
Output is correct |
58 |
Correct |
19 ms |
8696 KB |
Output is correct |
59 |
Correct |
23 ms |
9152 KB |
Output is correct |
60 |
Correct |
21 ms |
9360 KB |
Output is correct |
61 |
Correct |
29 ms |
9568 KB |
Output is correct |
62 |
Correct |
21 ms |
9776 KB |
Output is correct |
63 |
Correct |
29 ms |
9856 KB |
Output is correct |
64 |
Correct |
21 ms |
10172 KB |
Output is correct |
65 |
Correct |
24 ms |
10372 KB |
Output is correct |
66 |
Correct |
28 ms |
10660 KB |
Output is correct |
67 |
Correct |
27 ms |
10660 KB |
Output is correct |
68 |
Correct |
5 ms |
10660 KB |
Output is correct |
69 |
Correct |
13 ms |
10660 KB |
Output is correct |
70 |
Correct |
14 ms |
10660 KB |
Output is correct |
71 |
Correct |
15 ms |
10660 KB |
Output is correct |
72 |
Correct |
13 ms |
10660 KB |
Output is correct |
73 |
Correct |
5 ms |
10660 KB |
Output is correct |
74 |
Correct |
14 ms |
10660 KB |
Output is correct |
75 |
Correct |
690 ms |
11888 KB |
Output is correct |
76 |
Correct |
1264 ms |
12052 KB |
Output is correct |
77 |
Correct |
1392 ms |
12276 KB |
Output is correct |
78 |
Correct |
1298 ms |
12460 KB |
Output is correct |
79 |
Correct |
1289 ms |
12552 KB |
Output is correct |
80 |
Correct |
33 ms |
12772 KB |
Output is correct |
81 |
Correct |
25 ms |
12852 KB |
Output is correct |
82 |
Correct |
30 ms |
13060 KB |
Output is correct |
83 |
Correct |
34 ms |
13268 KB |
Output is correct |
84 |
Correct |
32 ms |
13476 KB |
Output is correct |
85 |
Correct |
33 ms |
13556 KB |
Output is correct |
86 |
Correct |
34 ms |
13892 KB |
Output is correct |
87 |
Correct |
26 ms |
13972 KB |
Output is correct |
88 |
Correct |
37 ms |
14308 KB |
Output is correct |
89 |
Correct |
30 ms |
14464 KB |
Output is correct |
90 |
Correct |
61 ms |
14724 KB |
Output is correct |
91 |
Correct |
48 ms |
15060 KB |
Output is correct |
92 |
Correct |
120 ms |
15188 KB |
Output is correct |
93 |
Correct |
91 ms |
15320 KB |
Output is correct |
94 |
Correct |
89 ms |
15684 KB |
Output is correct |
95 |
Correct |
106 ms |
15764 KB |
Output is correct |
96 |
Correct |
459 ms |
15960 KB |
Output is correct |
97 |
Correct |
1569 ms |
16320 KB |
Output is correct |
98 |
Execution timed out |
2070 ms |
16412 KB |
Time limit exceeded |
99 |
Halted |
0 ms |
0 KB |
- |