# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
418946 |
2021-06-06T09:05:58 Z |
SlavicG |
Toy Train (IOI17_train) |
C++17 |
|
973 ms |
1800 KB |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define GR(a,n,m) vector<vector<int>> a(n, vector<int>(m, 0));
const int N = 5005;
int n;
bool vis[N];
vector<int> adj[N], rev[N], a;
vector<int> F(vector<int> f, int p){
vector<int> ret;
vector<int> deg(n, 0);
for(int i = 0;i < n;i++){
for(auto x: adj[i]){
if(!vis[x])++deg[i];
}
}
for(auto x: f){
vis[x] = true;
}
while(sz(f) > 0)
{
int u = f.back();
ret.pb(u);
f.pop_back();
for(auto v: rev[u]){
if(!vis[v]){
--deg[v];
if(a[v] == p || !deg[v]){
vis[v] = true;
f.pb(v);
}
}
}
}
return ret;
}
vector<int> who_wins(vector<int> tempa, vector<int> r, vector<int> u, vector<int> v){
n = sz(tempa);
int M = sz(u);
a = tempa;
for(int i = 0;i < M;i++){
adj[u[i]].pb(v[i]);
rev[v[i]].pb(u[i]);
}
vector<int> ans(n, 0);
while(true)
{
vector<int> rm, c, fA;
for(int i = 0;i < n;i++){
if(vis[i])continue;
if(r[i])c.pb(i);
rm.pb(i);
}
fA = F(c, 1);
if(sz(rm) == sz(fA)){
for(auto x: rm)ans[x] = 1;
break;
}
vector<int> s, fAA(n, 0);
for(auto x: fA)fAA[x] = 1;
for(auto x: rm){
vis[x] = false;
if(!fAA[x])s.pb(x);
}
vector<int> fB = F(s, 0);
if(sz(fB) == sz(rm))break;
}
return ans;
}
/*
void solve()
{
int n, m;
cin >> n >> m;
vector<int> aa(n), rr(n), uu(m), vv(m);
forn(i,n)cin>>aa[i];
forn(i,n)cin>>rr[i];
forn(i,m)cin>>uu[i];
forn(i,m)cin>>vv[i];
vector<int> rasp = who_wins(aa,rr,uu,vv);
for(auto x: rasp)cout << x << " ";
}
int32_t main()
{
fastio;
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1204 KB |
Output is correct |
2 |
Correct |
7 ms |
1196 KB |
Output is correct |
3 |
Correct |
6 ms |
1228 KB |
Output is correct |
4 |
Correct |
7 ms |
1228 KB |
Output is correct |
5 |
Correct |
7 ms |
1220 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
6 ms |
1308 KB |
Output is correct |
9 |
Correct |
6 ms |
1228 KB |
Output is correct |
10 |
Correct |
5 ms |
1228 KB |
Output is correct |
11 |
Correct |
5 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
536 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
536 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
1536 KB |
Output is correct |
2 |
Correct |
334 ms |
1748 KB |
Output is correct |
3 |
Correct |
439 ms |
1780 KB |
Output is correct |
4 |
Correct |
10 ms |
1700 KB |
Output is correct |
5 |
Correct |
14 ms |
1736 KB |
Output is correct |
6 |
Correct |
15 ms |
1568 KB |
Output is correct |
7 |
Correct |
10 ms |
1612 KB |
Output is correct |
8 |
Correct |
9 ms |
1612 KB |
Output is correct |
9 |
Correct |
9 ms |
1780 KB |
Output is correct |
10 |
Correct |
9 ms |
1636 KB |
Output is correct |
11 |
Correct |
9 ms |
1612 KB |
Output is correct |
12 |
Correct |
8 ms |
1612 KB |
Output is correct |
13 |
Correct |
9 ms |
1612 KB |
Output is correct |
14 |
Correct |
9 ms |
1680 KB |
Output is correct |
15 |
Correct |
9 ms |
1612 KB |
Output is correct |
16 |
Correct |
9 ms |
1620 KB |
Output is correct |
17 |
Correct |
9 ms |
1612 KB |
Output is correct |
18 |
Correct |
550 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1356 KB |
Output is correct |
2 |
Correct |
9 ms |
1484 KB |
Output is correct |
3 |
Correct |
9 ms |
1700 KB |
Output is correct |
4 |
Correct |
12 ms |
1740 KB |
Output is correct |
5 |
Correct |
13 ms |
1696 KB |
Output is correct |
6 |
Correct |
13 ms |
1612 KB |
Output is correct |
7 |
Correct |
10 ms |
1612 KB |
Output is correct |
8 |
Correct |
9 ms |
1612 KB |
Output is correct |
9 |
Correct |
9 ms |
1612 KB |
Output is correct |
10 |
Correct |
9 ms |
1732 KB |
Output is correct |
11 |
Correct |
9 ms |
1740 KB |
Output is correct |
12 |
Correct |
10 ms |
1708 KB |
Output is correct |
13 |
Correct |
10 ms |
1612 KB |
Output is correct |
14 |
Correct |
9 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1484 KB |
Output is correct |
2 |
Correct |
9 ms |
1712 KB |
Output is correct |
3 |
Correct |
10 ms |
1700 KB |
Output is correct |
4 |
Correct |
9 ms |
1488 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
5 ms |
1228 KB |
Output is correct |
7 |
Correct |
8 ms |
1188 KB |
Output is correct |
8 |
Correct |
7 ms |
1228 KB |
Output is correct |
9 |
Correct |
9 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1204 KB |
Output is correct |
2 |
Correct |
7 ms |
1196 KB |
Output is correct |
3 |
Correct |
6 ms |
1228 KB |
Output is correct |
4 |
Correct |
7 ms |
1228 KB |
Output is correct |
5 |
Correct |
7 ms |
1220 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
6 ms |
1308 KB |
Output is correct |
9 |
Correct |
6 ms |
1228 KB |
Output is correct |
10 |
Correct |
5 ms |
1228 KB |
Output is correct |
11 |
Correct |
5 ms |
1228 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
536 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
536 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
172 ms |
1536 KB |
Output is correct |
33 |
Correct |
334 ms |
1748 KB |
Output is correct |
34 |
Correct |
439 ms |
1780 KB |
Output is correct |
35 |
Correct |
10 ms |
1700 KB |
Output is correct |
36 |
Correct |
14 ms |
1736 KB |
Output is correct |
37 |
Correct |
15 ms |
1568 KB |
Output is correct |
38 |
Correct |
10 ms |
1612 KB |
Output is correct |
39 |
Correct |
9 ms |
1612 KB |
Output is correct |
40 |
Correct |
9 ms |
1780 KB |
Output is correct |
41 |
Correct |
9 ms |
1636 KB |
Output is correct |
42 |
Correct |
9 ms |
1612 KB |
Output is correct |
43 |
Correct |
8 ms |
1612 KB |
Output is correct |
44 |
Correct |
9 ms |
1612 KB |
Output is correct |
45 |
Correct |
9 ms |
1680 KB |
Output is correct |
46 |
Correct |
9 ms |
1612 KB |
Output is correct |
47 |
Correct |
9 ms |
1620 KB |
Output is correct |
48 |
Correct |
9 ms |
1612 KB |
Output is correct |
49 |
Correct |
550 ms |
1364 KB |
Output is correct |
50 |
Correct |
8 ms |
1356 KB |
Output is correct |
51 |
Correct |
9 ms |
1484 KB |
Output is correct |
52 |
Correct |
9 ms |
1700 KB |
Output is correct |
53 |
Correct |
12 ms |
1740 KB |
Output is correct |
54 |
Correct |
13 ms |
1696 KB |
Output is correct |
55 |
Correct |
13 ms |
1612 KB |
Output is correct |
56 |
Correct |
10 ms |
1612 KB |
Output is correct |
57 |
Correct |
9 ms |
1612 KB |
Output is correct |
58 |
Correct |
9 ms |
1612 KB |
Output is correct |
59 |
Correct |
9 ms |
1732 KB |
Output is correct |
60 |
Correct |
9 ms |
1740 KB |
Output is correct |
61 |
Correct |
10 ms |
1708 KB |
Output is correct |
62 |
Correct |
10 ms |
1612 KB |
Output is correct |
63 |
Correct |
9 ms |
1612 KB |
Output is correct |
64 |
Correct |
10 ms |
1484 KB |
Output is correct |
65 |
Correct |
9 ms |
1712 KB |
Output is correct |
66 |
Correct |
10 ms |
1700 KB |
Output is correct |
67 |
Correct |
9 ms |
1488 KB |
Output is correct |
68 |
Correct |
1 ms |
588 KB |
Output is correct |
69 |
Correct |
5 ms |
1228 KB |
Output is correct |
70 |
Correct |
8 ms |
1188 KB |
Output is correct |
71 |
Correct |
7 ms |
1228 KB |
Output is correct |
72 |
Correct |
9 ms |
1228 KB |
Output is correct |
73 |
Correct |
2 ms |
656 KB |
Output is correct |
74 |
Correct |
7 ms |
1104 KB |
Output is correct |
75 |
Correct |
250 ms |
1716 KB |
Output is correct |
76 |
Correct |
362 ms |
1800 KB |
Output is correct |
77 |
Correct |
503 ms |
1796 KB |
Output is correct |
78 |
Correct |
483 ms |
1740 KB |
Output is correct |
79 |
Correct |
473 ms |
1740 KB |
Output is correct |
80 |
Correct |
10 ms |
1612 KB |
Output is correct |
81 |
Correct |
11 ms |
1700 KB |
Output is correct |
82 |
Correct |
12 ms |
1716 KB |
Output is correct |
83 |
Correct |
11 ms |
1612 KB |
Output is correct |
84 |
Correct |
14 ms |
1652 KB |
Output is correct |
85 |
Correct |
11 ms |
1612 KB |
Output is correct |
86 |
Correct |
13 ms |
1612 KB |
Output is correct |
87 |
Correct |
10 ms |
1728 KB |
Output is correct |
88 |
Correct |
15 ms |
1624 KB |
Output is correct |
89 |
Correct |
13 ms |
1704 KB |
Output is correct |
90 |
Correct |
24 ms |
1716 KB |
Output is correct |
91 |
Correct |
19 ms |
1712 KB |
Output is correct |
92 |
Correct |
35 ms |
1712 KB |
Output is correct |
93 |
Correct |
37 ms |
1704 KB |
Output is correct |
94 |
Correct |
44 ms |
1712 KB |
Output is correct |
95 |
Correct |
38 ms |
1612 KB |
Output is correct |
96 |
Correct |
114 ms |
1648 KB |
Output is correct |
97 |
Correct |
621 ms |
1716 KB |
Output is correct |
98 |
Correct |
969 ms |
1684 KB |
Output is correct |
99 |
Correct |
973 ms |
1768 KB |
Output is correct |
100 |
Correct |
527 ms |
1316 KB |
Output is correct |