# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
431248 |
2021-06-17T10:30:43 Z |
rainboy |
Toy Train (IOI17_train) |
C++ |
|
416 ms |
1328 KB |
/* https://codeforces.com/blog/entry/53550?#comment-375660 (Swistakk) */
#include "train.h"
#include <stdlib.h>
using namespace std;
const int N = 5000;
typedef vector<int> vi;
int *ej[N], eo[N], dd_[N], dd[N], qu[N]; char rr[N];
vi who_wins(vi aa, vi rr_, vi uu, vi vv) {
int n = aa.size(), m = uu.size(), h, i, j, o, cnt;
vi ans(n);
for (i = 0; i < n; i++)
rr[i] = rr_[i];
for (h = 0; h < m; h++)
dd_[uu[h]]++, eo[vv[h]]++;
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(eo[i] * sizeof *ej[i]), eo[i] = 0;
for (h = 0; h < m; h++)
ej[vv[h]][eo[vv[h]]++] = uu[h];
again:
cnt = 0;
for (i = 0; i < n; i++) {
dd[i] = aa[i] == 1 ? 1 : dd_[i], ans[i] = 0;
if (rr[i])
dd[i] = 0, ans[i] = 1, qu[cnt++] = i;
}
while (cnt) {
i = qu[--cnt];
for (o = eo[i]; o--; ) {
j = ej[i][o];
if (--dd[j] == 0)
ans[j] = 1, qu[cnt++] = j;
}
}
cnt = 0;
for (i = 0; i < n; i++) {
dd[i] = aa[i] == 0 ? 1 : dd_[i];
if (!ans[i])
dd[i] = 0, qu[cnt++] = i;
}
while (cnt) {
i = qu[--cnt];
for (o = eo[i]; o--; ) {
j = ej[i][o];
if (--dd[j] == 0) {
ans[j] = 0, qu[cnt++] = j;
if (rr[j]) {
rr[j] = 0;
goto again;
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
732 KB |
Output is correct |
2 |
Correct |
150 ms |
816 KB |
Output is correct |
3 |
Correct |
147 ms |
828 KB |
Output is correct |
4 |
Correct |
163 ms |
816 KB |
Output is correct |
5 |
Correct |
143 ms |
820 KB |
Output is correct |
6 |
Correct |
137 ms |
820 KB |
Output is correct |
7 |
Correct |
179 ms |
816 KB |
Output is correct |
8 |
Correct |
26 ms |
836 KB |
Output is correct |
9 |
Correct |
117 ms |
808 KB |
Output is correct |
10 |
Correct |
91 ms |
796 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
252 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
284 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
996 KB |
Output is correct |
2 |
Correct |
171 ms |
1192 KB |
Output is correct |
3 |
Correct |
210 ms |
1328 KB |
Output is correct |
4 |
Correct |
11 ms |
1100 KB |
Output is correct |
5 |
Correct |
58 ms |
1168 KB |
Output is correct |
6 |
Correct |
60 ms |
1180 KB |
Output is correct |
7 |
Correct |
8 ms |
1076 KB |
Output is correct |
8 |
Correct |
8 ms |
1196 KB |
Output is correct |
9 |
Correct |
8 ms |
1144 KB |
Output is correct |
10 |
Correct |
7 ms |
1052 KB |
Output is correct |
11 |
Correct |
9 ms |
1100 KB |
Output is correct |
12 |
Correct |
6 ms |
1100 KB |
Output is correct |
13 |
Correct |
7 ms |
1100 KB |
Output is correct |
14 |
Correct |
7 ms |
1100 KB |
Output is correct |
15 |
Correct |
8 ms |
1072 KB |
Output is correct |
16 |
Correct |
7 ms |
1100 KB |
Output is correct |
17 |
Correct |
9 ms |
1100 KB |
Output is correct |
18 |
Correct |
317 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
860 KB |
Output is correct |
2 |
Correct |
8 ms |
1100 KB |
Output is correct |
3 |
Correct |
16 ms |
1216 KB |
Output is correct |
4 |
Correct |
288 ms |
1172 KB |
Output is correct |
5 |
Correct |
17 ms |
1192 KB |
Output is correct |
6 |
Correct |
19 ms |
1052 KB |
Output is correct |
7 |
Correct |
37 ms |
1152 KB |
Output is correct |
8 |
Correct |
89 ms |
1144 KB |
Output is correct |
9 |
Correct |
154 ms |
1116 KB |
Output is correct |
10 |
Correct |
7 ms |
1100 KB |
Output is correct |
11 |
Correct |
9 ms |
1100 KB |
Output is correct |
12 |
Correct |
8 ms |
1068 KB |
Output is correct |
13 |
Correct |
8 ms |
1192 KB |
Output is correct |
14 |
Correct |
7 ms |
1032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
972 KB |
Output is correct |
2 |
Correct |
7 ms |
1064 KB |
Output is correct |
3 |
Correct |
8 ms |
1148 KB |
Output is correct |
4 |
Correct |
8 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Correct |
6 ms |
692 KB |
Output is correct |
8 |
Correct |
5 ms |
828 KB |
Output is correct |
9 |
Correct |
6 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
732 KB |
Output is correct |
2 |
Correct |
150 ms |
816 KB |
Output is correct |
3 |
Correct |
147 ms |
828 KB |
Output is correct |
4 |
Correct |
163 ms |
816 KB |
Output is correct |
5 |
Correct |
143 ms |
820 KB |
Output is correct |
6 |
Correct |
137 ms |
820 KB |
Output is correct |
7 |
Correct |
179 ms |
816 KB |
Output is correct |
8 |
Correct |
26 ms |
836 KB |
Output is correct |
9 |
Correct |
117 ms |
808 KB |
Output is correct |
10 |
Correct |
91 ms |
796 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
252 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
284 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
284 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
89 ms |
996 KB |
Output is correct |
33 |
Correct |
171 ms |
1192 KB |
Output is correct |
34 |
Correct |
210 ms |
1328 KB |
Output is correct |
35 |
Correct |
11 ms |
1100 KB |
Output is correct |
36 |
Correct |
58 ms |
1168 KB |
Output is correct |
37 |
Correct |
60 ms |
1180 KB |
Output is correct |
38 |
Correct |
8 ms |
1076 KB |
Output is correct |
39 |
Correct |
8 ms |
1196 KB |
Output is correct |
40 |
Correct |
8 ms |
1144 KB |
Output is correct |
41 |
Correct |
7 ms |
1052 KB |
Output is correct |
42 |
Correct |
9 ms |
1100 KB |
Output is correct |
43 |
Correct |
6 ms |
1100 KB |
Output is correct |
44 |
Correct |
7 ms |
1100 KB |
Output is correct |
45 |
Correct |
7 ms |
1100 KB |
Output is correct |
46 |
Correct |
8 ms |
1072 KB |
Output is correct |
47 |
Correct |
7 ms |
1100 KB |
Output is correct |
48 |
Correct |
9 ms |
1100 KB |
Output is correct |
49 |
Correct |
317 ms |
904 KB |
Output is correct |
50 |
Correct |
6 ms |
860 KB |
Output is correct |
51 |
Correct |
8 ms |
1100 KB |
Output is correct |
52 |
Correct |
16 ms |
1216 KB |
Output is correct |
53 |
Correct |
288 ms |
1172 KB |
Output is correct |
54 |
Correct |
17 ms |
1192 KB |
Output is correct |
55 |
Correct |
19 ms |
1052 KB |
Output is correct |
56 |
Correct |
37 ms |
1152 KB |
Output is correct |
57 |
Correct |
89 ms |
1144 KB |
Output is correct |
58 |
Correct |
154 ms |
1116 KB |
Output is correct |
59 |
Correct |
7 ms |
1100 KB |
Output is correct |
60 |
Correct |
9 ms |
1100 KB |
Output is correct |
61 |
Correct |
8 ms |
1068 KB |
Output is correct |
62 |
Correct |
8 ms |
1192 KB |
Output is correct |
63 |
Correct |
7 ms |
1032 KB |
Output is correct |
64 |
Correct |
7 ms |
972 KB |
Output is correct |
65 |
Correct |
7 ms |
1064 KB |
Output is correct |
66 |
Correct |
8 ms |
1148 KB |
Output is correct |
67 |
Correct |
8 ms |
1100 KB |
Output is correct |
68 |
Correct |
2 ms |
332 KB |
Output is correct |
69 |
Correct |
4 ms |
844 KB |
Output is correct |
70 |
Correct |
6 ms |
692 KB |
Output is correct |
71 |
Correct |
5 ms |
828 KB |
Output is correct |
72 |
Correct |
6 ms |
804 KB |
Output is correct |
73 |
Correct |
2 ms |
364 KB |
Output is correct |
74 |
Correct |
6 ms |
716 KB |
Output is correct |
75 |
Correct |
128 ms |
1160 KB |
Output is correct |
76 |
Correct |
191 ms |
1192 KB |
Output is correct |
77 |
Correct |
235 ms |
1192 KB |
Output is correct |
78 |
Correct |
249 ms |
1192 KB |
Output is correct |
79 |
Correct |
268 ms |
1200 KB |
Output is correct |
80 |
Correct |
8 ms |
1072 KB |
Output is correct |
81 |
Correct |
18 ms |
1100 KB |
Output is correct |
82 |
Correct |
23 ms |
1188 KB |
Output is correct |
83 |
Correct |
65 ms |
1160 KB |
Output is correct |
84 |
Correct |
14 ms |
1164 KB |
Output is correct |
85 |
Correct |
75 ms |
1100 KB |
Output is correct |
86 |
Correct |
36 ms |
1180 KB |
Output is correct |
87 |
Correct |
14 ms |
1196 KB |
Output is correct |
88 |
Correct |
95 ms |
1160 KB |
Output is correct |
89 |
Correct |
39 ms |
1192 KB |
Output is correct |
90 |
Correct |
71 ms |
1176 KB |
Output is correct |
91 |
Correct |
117 ms |
1176 KB |
Output is correct |
92 |
Correct |
104 ms |
1168 KB |
Output is correct |
93 |
Correct |
111 ms |
1176 KB |
Output is correct |
94 |
Correct |
132 ms |
1156 KB |
Output is correct |
95 |
Correct |
113 ms |
1052 KB |
Output is correct |
96 |
Correct |
87 ms |
1116 KB |
Output is correct |
97 |
Correct |
261 ms |
1068 KB |
Output is correct |
98 |
Correct |
404 ms |
1136 KB |
Output is correct |
99 |
Correct |
416 ms |
1124 KB |
Output is correct |
100 |
Correct |
261 ms |
900 KB |
Output is correct |