# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
74375 |
2018-08-31T12:48:54 Z |
Diuven |
Toy Train (IOI17_train) |
C++14 |
|
856 ms |
9548 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MX=5010;
vector<int> G[MX], H[MX];
int n;
bool tmp[MX];
vi win, A, R;
const vi& find(const vi &S, bool c){
static bool in[MX]={}; int deg[MX]={};
static vi T; static queue<int> Q;
for(int i=0; i<n; i++) in[i]=false, deg[i]=0;
T.clear();
for(int i=0; i<n; i++) if(win[i]<0)
for(int x:G[i]) deg[i]+=win[x]<0;
for(int x:S) in[x]=true, Q.push(x);
while(!Q.empty()){
int v=Q.front(); Q.pop();
for(int x:H[v]){
if(in[x] || win[x]>=0) continue;
if(A[x]==c) in[x]=true, Q.push(x);
else{
deg[x]--;
if(deg[x]==0) in[x]=true, Q.push(x);
}
}
}
for(int i=0; i<n; i++) if(in[i]) T.push_back(i);
return T;
}
vi who_wins(vi _A, vi _R, vi U, vi V) {
n=_A.size(); win.resize(n, -1);
A=_A, R=_R;
for(int i=0; i<(int)U.size(); i++){
G[U[i]].push_back(V[i]);
H[V[i]].push_back(U[i]);
}
vi S, T, X, Y;
while(true){
S.clear(), X.clear();
for(int i=0; i<n; i++) if(R[i] && win[i]<0) S.push_back(i);
T=find(S, 1);
for(int i=0; i<n; i++) tmp[i]=win[i]>=0;
for(int x:T) tmp[x]=true;
for(int i=0; i<n; i++) if(!tmp[i]) X.push_back(i);
if(X.empty()){
for(int x:T) win[x]=1;
break;
}
else{
Y=find(X, 0);
for(int x:Y) win[x]=0;
}
}
return win;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1276 KB |
Output is correct |
2 |
Correct |
11 ms |
1368 KB |
Output is correct |
3 |
Correct |
10 ms |
1496 KB |
Output is correct |
4 |
Correct |
8 ms |
1496 KB |
Output is correct |
5 |
Correct |
8 ms |
1496 KB |
Output is correct |
6 |
Correct |
7 ms |
1592 KB |
Output is correct |
7 |
Correct |
7 ms |
1620 KB |
Output is correct |
8 |
Correct |
8 ms |
1620 KB |
Output is correct |
9 |
Correct |
8 ms |
1620 KB |
Output is correct |
10 |
Correct |
7 ms |
1620 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1620 KB |
Output is correct |
4 |
Correct |
2 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1620 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
2 ms |
1620 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
2 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1620 KB |
Output is correct |
11 |
Correct |
2 ms |
1620 KB |
Output is correct |
12 |
Correct |
2 ms |
1620 KB |
Output is correct |
13 |
Correct |
2 ms |
1620 KB |
Output is correct |
14 |
Correct |
2 ms |
1620 KB |
Output is correct |
15 |
Correct |
2 ms |
1620 KB |
Output is correct |
16 |
Correct |
3 ms |
1620 KB |
Output is correct |
17 |
Correct |
4 ms |
1620 KB |
Output is correct |
18 |
Correct |
2 ms |
1620 KB |
Output is correct |
19 |
Correct |
2 ms |
1620 KB |
Output is correct |
20 |
Correct |
2 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
2028 KB |
Output is correct |
2 |
Correct |
302 ms |
2028 KB |
Output is correct |
3 |
Correct |
407 ms |
2028 KB |
Output is correct |
4 |
Correct |
13 ms |
2028 KB |
Output is correct |
5 |
Correct |
15 ms |
2028 KB |
Output is correct |
6 |
Correct |
15 ms |
2156 KB |
Output is correct |
7 |
Correct |
12 ms |
2364 KB |
Output is correct |
8 |
Correct |
13 ms |
2572 KB |
Output is correct |
9 |
Correct |
15 ms |
2780 KB |
Output is correct |
10 |
Correct |
14 ms |
2844 KB |
Output is correct |
11 |
Correct |
13 ms |
3040 KB |
Output is correct |
12 |
Correct |
12 ms |
3232 KB |
Output is correct |
13 |
Correct |
13 ms |
3544 KB |
Output is correct |
14 |
Correct |
20 ms |
3752 KB |
Output is correct |
15 |
Correct |
13 ms |
3960 KB |
Output is correct |
16 |
Correct |
12 ms |
4168 KB |
Output is correct |
17 |
Correct |
13 ms |
4376 KB |
Output is correct |
18 |
Correct |
575 ms |
4376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4376 KB |
Output is correct |
2 |
Correct |
11 ms |
4376 KB |
Output is correct |
3 |
Correct |
12 ms |
4444 KB |
Output is correct |
4 |
Correct |
12 ms |
4444 KB |
Output is correct |
5 |
Correct |
12 ms |
4444 KB |
Output is correct |
6 |
Correct |
12 ms |
4444 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
12 ms |
4444 KB |
Output is correct |
9 |
Correct |
12 ms |
4444 KB |
Output is correct |
10 |
Correct |
13 ms |
4444 KB |
Output is correct |
11 |
Correct |
12 ms |
4572 KB |
Output is correct |
12 |
Correct |
14 ms |
4604 KB |
Output is correct |
13 |
Correct |
13 ms |
4604 KB |
Output is correct |
14 |
Correct |
12 ms |
4604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4604 KB |
Output is correct |
2 |
Correct |
13 ms |
4604 KB |
Output is correct |
3 |
Correct |
15 ms |
4604 KB |
Output is correct |
4 |
Correct |
12 ms |
4604 KB |
Output is correct |
5 |
Correct |
3 ms |
4604 KB |
Output is correct |
6 |
Correct |
7 ms |
4604 KB |
Output is correct |
7 |
Correct |
8 ms |
4604 KB |
Output is correct |
8 |
Correct |
9 ms |
4604 KB |
Output is correct |
9 |
Correct |
10 ms |
4604 KB |
Output is correct |
10 |
Correct |
4 ms |
4604 KB |
Output is correct |
11 |
Correct |
8 ms |
4604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1276 KB |
Output is correct |
2 |
Correct |
11 ms |
1368 KB |
Output is correct |
3 |
Correct |
10 ms |
1496 KB |
Output is correct |
4 |
Correct |
8 ms |
1496 KB |
Output is correct |
5 |
Correct |
8 ms |
1496 KB |
Output is correct |
6 |
Correct |
7 ms |
1592 KB |
Output is correct |
7 |
Correct |
7 ms |
1620 KB |
Output is correct |
8 |
Correct |
8 ms |
1620 KB |
Output is correct |
9 |
Correct |
8 ms |
1620 KB |
Output is correct |
10 |
Correct |
7 ms |
1620 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
12 |
Correct |
2 ms |
1620 KB |
Output is correct |
13 |
Correct |
2 ms |
1620 KB |
Output is correct |
14 |
Correct |
2 ms |
1620 KB |
Output is correct |
15 |
Correct |
2 ms |
1620 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
2 ms |
1620 KB |
Output is correct |
18 |
Correct |
2 ms |
1620 KB |
Output is correct |
19 |
Correct |
2 ms |
1620 KB |
Output is correct |
20 |
Correct |
2 ms |
1620 KB |
Output is correct |
21 |
Correct |
2 ms |
1620 KB |
Output is correct |
22 |
Correct |
2 ms |
1620 KB |
Output is correct |
23 |
Correct |
2 ms |
1620 KB |
Output is correct |
24 |
Correct |
2 ms |
1620 KB |
Output is correct |
25 |
Correct |
2 ms |
1620 KB |
Output is correct |
26 |
Correct |
2 ms |
1620 KB |
Output is correct |
27 |
Correct |
3 ms |
1620 KB |
Output is correct |
28 |
Correct |
4 ms |
1620 KB |
Output is correct |
29 |
Correct |
2 ms |
1620 KB |
Output is correct |
30 |
Correct |
2 ms |
1620 KB |
Output is correct |
31 |
Correct |
2 ms |
1620 KB |
Output is correct |
32 |
Correct |
148 ms |
2028 KB |
Output is correct |
33 |
Correct |
302 ms |
2028 KB |
Output is correct |
34 |
Correct |
407 ms |
2028 KB |
Output is correct |
35 |
Correct |
13 ms |
2028 KB |
Output is correct |
36 |
Correct |
15 ms |
2028 KB |
Output is correct |
37 |
Correct |
15 ms |
2156 KB |
Output is correct |
38 |
Correct |
12 ms |
2364 KB |
Output is correct |
39 |
Correct |
13 ms |
2572 KB |
Output is correct |
40 |
Correct |
15 ms |
2780 KB |
Output is correct |
41 |
Correct |
14 ms |
2844 KB |
Output is correct |
42 |
Correct |
13 ms |
3040 KB |
Output is correct |
43 |
Correct |
12 ms |
3232 KB |
Output is correct |
44 |
Correct |
13 ms |
3544 KB |
Output is correct |
45 |
Correct |
20 ms |
3752 KB |
Output is correct |
46 |
Correct |
13 ms |
3960 KB |
Output is correct |
47 |
Correct |
12 ms |
4168 KB |
Output is correct |
48 |
Correct |
13 ms |
4376 KB |
Output is correct |
49 |
Correct |
575 ms |
4376 KB |
Output is correct |
50 |
Correct |
11 ms |
4376 KB |
Output is correct |
51 |
Correct |
11 ms |
4376 KB |
Output is correct |
52 |
Correct |
12 ms |
4444 KB |
Output is correct |
53 |
Correct |
12 ms |
4444 KB |
Output is correct |
54 |
Correct |
12 ms |
4444 KB |
Output is correct |
55 |
Correct |
12 ms |
4444 KB |
Output is correct |
56 |
Correct |
20 ms |
4444 KB |
Output is correct |
57 |
Correct |
12 ms |
4444 KB |
Output is correct |
58 |
Correct |
12 ms |
4444 KB |
Output is correct |
59 |
Correct |
13 ms |
4444 KB |
Output is correct |
60 |
Correct |
12 ms |
4572 KB |
Output is correct |
61 |
Correct |
14 ms |
4604 KB |
Output is correct |
62 |
Correct |
13 ms |
4604 KB |
Output is correct |
63 |
Correct |
12 ms |
4604 KB |
Output is correct |
64 |
Correct |
13 ms |
4604 KB |
Output is correct |
65 |
Correct |
13 ms |
4604 KB |
Output is correct |
66 |
Correct |
15 ms |
4604 KB |
Output is correct |
67 |
Correct |
12 ms |
4604 KB |
Output is correct |
68 |
Correct |
3 ms |
4604 KB |
Output is correct |
69 |
Correct |
7 ms |
4604 KB |
Output is correct |
70 |
Correct |
8 ms |
4604 KB |
Output is correct |
71 |
Correct |
9 ms |
4604 KB |
Output is correct |
72 |
Correct |
10 ms |
4604 KB |
Output is correct |
73 |
Correct |
4 ms |
4604 KB |
Output is correct |
74 |
Correct |
8 ms |
4604 KB |
Output is correct |
75 |
Correct |
209 ms |
4736 KB |
Output is correct |
76 |
Correct |
323 ms |
4952 KB |
Output is correct |
77 |
Correct |
445 ms |
5096 KB |
Output is correct |
78 |
Correct |
439 ms |
5416 KB |
Output is correct |
79 |
Correct |
437 ms |
5512 KB |
Output is correct |
80 |
Correct |
13 ms |
5704 KB |
Output is correct |
81 |
Correct |
13 ms |
5912 KB |
Output is correct |
82 |
Correct |
14 ms |
6108 KB |
Output is correct |
83 |
Correct |
14 ms |
6328 KB |
Output is correct |
84 |
Correct |
15 ms |
6536 KB |
Output is correct |
85 |
Correct |
13 ms |
6616 KB |
Output is correct |
86 |
Correct |
14 ms |
6952 KB |
Output is correct |
87 |
Correct |
13 ms |
7160 KB |
Output is correct |
88 |
Correct |
17 ms |
7368 KB |
Output is correct |
89 |
Correct |
14 ms |
7564 KB |
Output is correct |
90 |
Correct |
23 ms |
7772 KB |
Output is correct |
91 |
Correct |
21 ms |
7992 KB |
Output is correct |
92 |
Correct |
35 ms |
8180 KB |
Output is correct |
93 |
Correct |
35 ms |
8408 KB |
Output is correct |
94 |
Correct |
35 ms |
8596 KB |
Output is correct |
95 |
Correct |
64 ms |
8828 KB |
Output is correct |
96 |
Correct |
130 ms |
9032 KB |
Output is correct |
97 |
Correct |
533 ms |
9316 KB |
Output is correct |
98 |
Correct |
825 ms |
9428 KB |
Output is correct |
99 |
Correct |
856 ms |
9500 KB |
Output is correct |
100 |
Correct |
600 ms |
9548 KB |
Output is correct |