# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
575405 |
2022-06-10T10:20:28 Z |
KoD |
Toy Train (IOI17_train) |
C++17 |
|
1050 ms |
1720 KB |
#include "train.h"
#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
const int n = (int)a.size();
const int m = (int)u.size();
vector<int> ret(n, -1);
vector<vector<int>> graph(n), rev_graph(n);
for (int i = 0; i < m; ++i) {
graph[u[i]].push_back(v[i]);
rev_graph[v[i]].push_back(u[i]);
}
const auto expand = [&](vector<char>& set, const int side) {
vector<int> deg(n);
std::queue<int> que;
for (int u = 0; u < n; ++u) {
for (const int v : graph[u]) {
if (ret[v] == -1) {
deg[u] += 1;
}
}
if (set[u]) {
que.push(u);
}
}
while (!que.empty()) {
const int u = que.front();
que.pop();
for (const int v : rev_graph[u]) {
if (ret[v] != -1 or set[v]) {
continue;
}
if (a[v] == side) {
set[v] = true;
que.push(v);
} else {
deg[v] -= 1;
if (deg[v] == 0) {
set[v] = true;
que.push(v);
}
}
}
}
};
while (true) {
if (std::all_of(ret.begin(), ret.end(), [&](const int x) { return x != -1; })) {
return ret;
}
vector<char> A_set(n);
for (int u = 0; u < n; ++u) {
if (ret[u] == -1 and r[u]) {
A_set[u] = true;
}
}
expand(A_set, 1);
bool A_win = true;
for (int u = 0; u < n; ++u) {
if (ret[u] == -1 and !A_set[u]) {
A_win = false;
break;
}
}
if (A_win) {
for (int u = 0; u < n; ++u) {
if (A_set[u]) {
ret[u] = 1;
}
}
} else {
vector<char> B_set(n);
for (int u = 0; u < n; ++u) {
if (ret[u] == -1 and !A_set[u]) {
B_set[u] = true;
}
}
expand(B_set, 0);
for (int u = 0; u < n; ++u) {
if (B_set[u]) {
ret[u] = 0;
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
7 ms |
1108 KB |
Output is correct |
3 |
Correct |
5 ms |
1108 KB |
Output is correct |
4 |
Correct |
6 ms |
1080 KB |
Output is correct |
5 |
Correct |
6 ms |
1108 KB |
Output is correct |
6 |
Correct |
5 ms |
1108 KB |
Output is correct |
7 |
Correct |
5 ms |
1208 KB |
Output is correct |
8 |
Correct |
6 ms |
1184 KB |
Output is correct |
9 |
Correct |
5 ms |
1232 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
1648 KB |
Output is correct |
2 |
Correct |
337 ms |
1648 KB |
Output is correct |
3 |
Correct |
480 ms |
1648 KB |
Output is correct |
4 |
Correct |
8 ms |
1620 KB |
Output is correct |
5 |
Correct |
9 ms |
1620 KB |
Output is correct |
6 |
Correct |
9 ms |
1564 KB |
Output is correct |
7 |
Correct |
8 ms |
1588 KB |
Output is correct |
8 |
Correct |
8 ms |
1596 KB |
Output is correct |
9 |
Correct |
7 ms |
1492 KB |
Output is correct |
10 |
Correct |
8 ms |
1476 KB |
Output is correct |
11 |
Correct |
8 ms |
1484 KB |
Output is correct |
12 |
Correct |
8 ms |
1492 KB |
Output is correct |
13 |
Correct |
8 ms |
1588 KB |
Output is correct |
14 |
Correct |
8 ms |
1592 KB |
Output is correct |
15 |
Correct |
11 ms |
1616 KB |
Output is correct |
16 |
Correct |
10 ms |
1600 KB |
Output is correct |
17 |
Correct |
8 ms |
1600 KB |
Output is correct |
18 |
Correct |
517 ms |
1256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1332 KB |
Output is correct |
2 |
Correct |
7 ms |
1492 KB |
Output is correct |
3 |
Correct |
8 ms |
1492 KB |
Output is correct |
4 |
Correct |
8 ms |
1492 KB |
Output is correct |
5 |
Correct |
10 ms |
1488 KB |
Output is correct |
6 |
Correct |
7 ms |
1492 KB |
Output is correct |
7 |
Correct |
9 ms |
1492 KB |
Output is correct |
8 |
Correct |
10 ms |
1464 KB |
Output is correct |
9 |
Correct |
8 ms |
1464 KB |
Output is correct |
10 |
Correct |
9 ms |
1620 KB |
Output is correct |
11 |
Correct |
8 ms |
1596 KB |
Output is correct |
12 |
Correct |
8 ms |
1596 KB |
Output is correct |
13 |
Correct |
8 ms |
1492 KB |
Output is correct |
14 |
Correct |
8 ms |
1432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1592 KB |
Output is correct |
2 |
Correct |
8 ms |
1504 KB |
Output is correct |
3 |
Correct |
9 ms |
1620 KB |
Output is correct |
4 |
Correct |
7 ms |
1476 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
1080 KB |
Output is correct |
7 |
Correct |
5 ms |
940 KB |
Output is correct |
8 |
Correct |
6 ms |
1076 KB |
Output is correct |
9 |
Correct |
6 ms |
976 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
8 ms |
928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
7 ms |
1108 KB |
Output is correct |
3 |
Correct |
5 ms |
1108 KB |
Output is correct |
4 |
Correct |
6 ms |
1080 KB |
Output is correct |
5 |
Correct |
6 ms |
1108 KB |
Output is correct |
6 |
Correct |
5 ms |
1108 KB |
Output is correct |
7 |
Correct |
5 ms |
1208 KB |
Output is correct |
8 |
Correct |
6 ms |
1184 KB |
Output is correct |
9 |
Correct |
5 ms |
1232 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
296 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
296 KB |
Output is correct |
28 |
Correct |
1 ms |
296 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
300 KB |
Output is correct |
32 |
Correct |
165 ms |
1648 KB |
Output is correct |
33 |
Correct |
337 ms |
1648 KB |
Output is correct |
34 |
Correct |
480 ms |
1648 KB |
Output is correct |
35 |
Correct |
8 ms |
1620 KB |
Output is correct |
36 |
Correct |
9 ms |
1620 KB |
Output is correct |
37 |
Correct |
9 ms |
1564 KB |
Output is correct |
38 |
Correct |
8 ms |
1588 KB |
Output is correct |
39 |
Correct |
8 ms |
1596 KB |
Output is correct |
40 |
Correct |
7 ms |
1492 KB |
Output is correct |
41 |
Correct |
8 ms |
1476 KB |
Output is correct |
42 |
Correct |
8 ms |
1484 KB |
Output is correct |
43 |
Correct |
8 ms |
1492 KB |
Output is correct |
44 |
Correct |
8 ms |
1588 KB |
Output is correct |
45 |
Correct |
8 ms |
1592 KB |
Output is correct |
46 |
Correct |
11 ms |
1616 KB |
Output is correct |
47 |
Correct |
10 ms |
1600 KB |
Output is correct |
48 |
Correct |
8 ms |
1600 KB |
Output is correct |
49 |
Correct |
517 ms |
1256 KB |
Output is correct |
50 |
Correct |
7 ms |
1332 KB |
Output is correct |
51 |
Correct |
7 ms |
1492 KB |
Output is correct |
52 |
Correct |
8 ms |
1492 KB |
Output is correct |
53 |
Correct |
8 ms |
1492 KB |
Output is correct |
54 |
Correct |
10 ms |
1488 KB |
Output is correct |
55 |
Correct |
7 ms |
1492 KB |
Output is correct |
56 |
Correct |
9 ms |
1492 KB |
Output is correct |
57 |
Correct |
10 ms |
1464 KB |
Output is correct |
58 |
Correct |
8 ms |
1464 KB |
Output is correct |
59 |
Correct |
9 ms |
1620 KB |
Output is correct |
60 |
Correct |
8 ms |
1596 KB |
Output is correct |
61 |
Correct |
8 ms |
1596 KB |
Output is correct |
62 |
Correct |
8 ms |
1492 KB |
Output is correct |
63 |
Correct |
8 ms |
1432 KB |
Output is correct |
64 |
Correct |
9 ms |
1592 KB |
Output is correct |
65 |
Correct |
8 ms |
1504 KB |
Output is correct |
66 |
Correct |
9 ms |
1620 KB |
Output is correct |
67 |
Correct |
7 ms |
1476 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
4 ms |
1080 KB |
Output is correct |
70 |
Correct |
5 ms |
940 KB |
Output is correct |
71 |
Correct |
6 ms |
1076 KB |
Output is correct |
72 |
Correct |
6 ms |
976 KB |
Output is correct |
73 |
Correct |
3 ms |
468 KB |
Output is correct |
74 |
Correct |
8 ms |
928 KB |
Output is correct |
75 |
Correct |
235 ms |
1620 KB |
Output is correct |
76 |
Correct |
397 ms |
1640 KB |
Output is correct |
77 |
Correct |
516 ms |
1632 KB |
Output is correct |
78 |
Correct |
532 ms |
1640 KB |
Output is correct |
79 |
Correct |
536 ms |
1636 KB |
Output is correct |
80 |
Correct |
8 ms |
1588 KB |
Output is correct |
81 |
Correct |
8 ms |
1632 KB |
Output is correct |
82 |
Correct |
10 ms |
1620 KB |
Output is correct |
83 |
Correct |
9 ms |
1596 KB |
Output is correct |
84 |
Correct |
10 ms |
1600 KB |
Output is correct |
85 |
Correct |
9 ms |
1492 KB |
Output is correct |
86 |
Correct |
12 ms |
1600 KB |
Output is correct |
87 |
Correct |
11 ms |
1492 KB |
Output is correct |
88 |
Correct |
13 ms |
1628 KB |
Output is correct |
89 |
Correct |
11 ms |
1620 KB |
Output is correct |
90 |
Correct |
19 ms |
1608 KB |
Output is correct |
91 |
Correct |
23 ms |
1576 KB |
Output is correct |
92 |
Correct |
33 ms |
1604 KB |
Output is correct |
93 |
Correct |
34 ms |
1720 KB |
Output is correct |
94 |
Correct |
34 ms |
1596 KB |
Output is correct |
95 |
Correct |
36 ms |
1608 KB |
Output is correct |
96 |
Correct |
104 ms |
1504 KB |
Output is correct |
97 |
Correct |
621 ms |
1620 KB |
Output is correct |
98 |
Correct |
916 ms |
1572 KB |
Output is correct |
99 |
Correct |
1050 ms |
1556 KB |
Output is correct |
100 |
Correct |
491 ms |
1248 KB |
Output is correct |