# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
239495 |
2020-06-15T22:33:15 Z |
Jatana |
Toy Train (IOI17_train) |
C++17 |
|
593 ms |
1792 KB |
#include "train.h"
#include <iostream>
#include <numeric>
#define le(v) ((int)v.size())
#define x first
#define y second
#define pb push_back
#define f(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int n, m;
vector<int> who;
vector<vector<int>> g;
vector<vector<int>> reg;
vector<int> c;
vector<int> ic;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
g.clear();
c.clear();
who.clear();
who = a;
n = le(a);
m = le(u);
ic = c = r;
g.resize(n);
reg.resize(n);
// cerr <<n << endl;
// f(i, m) {
// cerr << u[i] << " " << v[i] << endl;
// }
// return c;
f(i, m) {
g[u[i]].pb(v[i]);
reg[v[i]].pb(u[i]);
}
vector<bool> dead(n, false);
while (true) {
f(i, n) {
if (dead[i]) {
c[i] = 0;
} else c[i] = ic[i];
}
{
vector<int> deq(n);
iota(deq.begin(), deq.end(), 0);
while (!deq.empty()) {
int i = deq.back(); deq.pop_back();
if (dead[i]) continue;
if (c[i] == 1) continue;
if (who[i] == 1) {
// indefinitely
for (int sub : g[i]) {
if (c[sub]) {
c[i] = 1;
break;
}
}
} else {
// finitely
bool some = false;
for (int sub : g[i]) {
if (!c[sub]) {
some = true;
break;
}
}
if (!some) {
c[i] = 1;
}
}
if (c[i] == 1) {
for (int sub : reg[i]) {
deq.pb(sub);
}
}
}
}
while (true) {
vector<int> was = c;
for (int i = 0; i < n; i++) {
if (dead[i]) continue;
if (c[i] == 0) continue;
if (who[i] == 1) {
// indefinitely
bool some = false;
for (int sub : g[i]) {
if (c[sub]) {
some = true;
break;
}
}
if (!some) {
c[i] = 0;
}
} else {
// finitely
for (int sub : g[i]) {
if (!c[sub]) {
c[i] = 0;
break;
}
}
}
}
if (was == c) break;
}
bool _new = false;
f(i, n) {
if (!c[i]) {
if (!dead[i]) _new = true;
dead[i] = true;
}
}
if (!_new) break;
}
vector<int> out(n);
f(i, n) {
if (dead[i]) {
out[i] = 0;
} else out[i] = 1;
}
return out;
// vector<int> res(a.size());
// for(int i = 0; i < (int)res.size(); i++)
// res[i] = i % 2;
// return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1152 KB |
Output is correct |
2 |
Correct |
12 ms |
1152 KB |
Output is correct |
3 |
Correct |
11 ms |
1152 KB |
Output is correct |
4 |
Correct |
14 ms |
1152 KB |
Output is correct |
5 |
Correct |
11 ms |
1152 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
10 ms |
1152 KB |
Output is correct |
8 |
Correct |
10 ms |
1152 KB |
Output is correct |
9 |
Correct |
10 ms |
1152 KB |
Output is correct |
10 |
Correct |
9 ms |
1152 KB |
Output is correct |
11 |
Correct |
8 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
1588 KB |
Output is correct |
2 |
Correct |
222 ms |
1656 KB |
Output is correct |
3 |
Correct |
282 ms |
1536 KB |
Output is correct |
4 |
Correct |
16 ms |
1536 KB |
Output is correct |
5 |
Correct |
15 ms |
1664 KB |
Output is correct |
6 |
Correct |
16 ms |
1664 KB |
Output is correct |
7 |
Correct |
14 ms |
1664 KB |
Output is correct |
8 |
Correct |
14 ms |
1664 KB |
Output is correct |
9 |
Correct |
13 ms |
1664 KB |
Output is correct |
10 |
Correct |
14 ms |
1664 KB |
Output is correct |
11 |
Correct |
14 ms |
1536 KB |
Output is correct |
12 |
Correct |
13 ms |
1536 KB |
Output is correct |
13 |
Correct |
14 ms |
1792 KB |
Output is correct |
14 |
Correct |
15 ms |
1788 KB |
Output is correct |
15 |
Correct |
14 ms |
1792 KB |
Output is correct |
16 |
Correct |
14 ms |
1792 KB |
Output is correct |
17 |
Correct |
14 ms |
1792 KB |
Output is correct |
18 |
Correct |
342 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1280 KB |
Output is correct |
2 |
Correct |
14 ms |
1280 KB |
Output is correct |
3 |
Correct |
15 ms |
1408 KB |
Output is correct |
4 |
Correct |
14 ms |
1408 KB |
Output is correct |
5 |
Correct |
16 ms |
1488 KB |
Output is correct |
6 |
Correct |
16 ms |
1408 KB |
Output is correct |
7 |
Correct |
15 ms |
1408 KB |
Output is correct |
8 |
Correct |
13 ms |
1408 KB |
Output is correct |
9 |
Correct |
13 ms |
1408 KB |
Output is correct |
10 |
Correct |
14 ms |
1408 KB |
Output is correct |
11 |
Correct |
14 ms |
1408 KB |
Output is correct |
12 |
Correct |
15 ms |
1408 KB |
Output is correct |
13 |
Correct |
15 ms |
1408 KB |
Output is correct |
14 |
Correct |
14 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1408 KB |
Output is correct |
2 |
Correct |
15 ms |
1536 KB |
Output is correct |
3 |
Correct |
17 ms |
1408 KB |
Output is correct |
4 |
Correct |
13 ms |
1408 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
10 ms |
1024 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
10 ms |
1024 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
10 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1152 KB |
Output is correct |
2 |
Correct |
12 ms |
1152 KB |
Output is correct |
3 |
Correct |
11 ms |
1152 KB |
Output is correct |
4 |
Correct |
14 ms |
1152 KB |
Output is correct |
5 |
Correct |
11 ms |
1152 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
10 ms |
1152 KB |
Output is correct |
8 |
Correct |
10 ms |
1152 KB |
Output is correct |
9 |
Correct |
10 ms |
1152 KB |
Output is correct |
10 |
Correct |
9 ms |
1152 KB |
Output is correct |
11 |
Correct |
8 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
4 ms |
256 KB |
Output is correct |
24 |
Correct |
4 ms |
256 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
256 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
256 KB |
Output is correct |
29 |
Correct |
4 ms |
256 KB |
Output is correct |
30 |
Correct |
5 ms |
256 KB |
Output is correct |
31 |
Correct |
4 ms |
256 KB |
Output is correct |
32 |
Correct |
112 ms |
1588 KB |
Output is correct |
33 |
Correct |
222 ms |
1656 KB |
Output is correct |
34 |
Correct |
282 ms |
1536 KB |
Output is correct |
35 |
Correct |
16 ms |
1536 KB |
Output is correct |
36 |
Correct |
15 ms |
1664 KB |
Output is correct |
37 |
Correct |
16 ms |
1664 KB |
Output is correct |
38 |
Correct |
14 ms |
1664 KB |
Output is correct |
39 |
Correct |
14 ms |
1664 KB |
Output is correct |
40 |
Correct |
13 ms |
1664 KB |
Output is correct |
41 |
Correct |
14 ms |
1664 KB |
Output is correct |
42 |
Correct |
14 ms |
1536 KB |
Output is correct |
43 |
Correct |
13 ms |
1536 KB |
Output is correct |
44 |
Correct |
14 ms |
1792 KB |
Output is correct |
45 |
Correct |
15 ms |
1788 KB |
Output is correct |
46 |
Correct |
14 ms |
1792 KB |
Output is correct |
47 |
Correct |
14 ms |
1792 KB |
Output is correct |
48 |
Correct |
14 ms |
1792 KB |
Output is correct |
49 |
Correct |
342 ms |
1400 KB |
Output is correct |
50 |
Correct |
12 ms |
1280 KB |
Output is correct |
51 |
Correct |
14 ms |
1280 KB |
Output is correct |
52 |
Correct |
15 ms |
1408 KB |
Output is correct |
53 |
Correct |
14 ms |
1408 KB |
Output is correct |
54 |
Correct |
16 ms |
1488 KB |
Output is correct |
55 |
Correct |
16 ms |
1408 KB |
Output is correct |
56 |
Correct |
15 ms |
1408 KB |
Output is correct |
57 |
Correct |
13 ms |
1408 KB |
Output is correct |
58 |
Correct |
13 ms |
1408 KB |
Output is correct |
59 |
Correct |
14 ms |
1408 KB |
Output is correct |
60 |
Correct |
14 ms |
1408 KB |
Output is correct |
61 |
Correct |
15 ms |
1408 KB |
Output is correct |
62 |
Correct |
15 ms |
1408 KB |
Output is correct |
63 |
Correct |
14 ms |
1408 KB |
Output is correct |
64 |
Correct |
15 ms |
1408 KB |
Output is correct |
65 |
Correct |
15 ms |
1536 KB |
Output is correct |
66 |
Correct |
17 ms |
1408 KB |
Output is correct |
67 |
Correct |
13 ms |
1408 KB |
Output is correct |
68 |
Correct |
5 ms |
384 KB |
Output is correct |
69 |
Correct |
9 ms |
1024 KB |
Output is correct |
70 |
Correct |
10 ms |
1024 KB |
Output is correct |
71 |
Correct |
12 ms |
1024 KB |
Output is correct |
72 |
Correct |
10 ms |
1024 KB |
Output is correct |
73 |
Correct |
6 ms |
512 KB |
Output is correct |
74 |
Correct |
10 ms |
896 KB |
Output is correct |
75 |
Correct |
190 ms |
1784 KB |
Output is correct |
76 |
Correct |
299 ms |
1784 KB |
Output is correct |
77 |
Correct |
398 ms |
1664 KB |
Output is correct |
78 |
Correct |
395 ms |
1784 KB |
Output is correct |
79 |
Correct |
397 ms |
1664 KB |
Output is correct |
80 |
Correct |
15 ms |
1664 KB |
Output is correct |
81 |
Correct |
15 ms |
1664 KB |
Output is correct |
82 |
Correct |
17 ms |
1664 KB |
Output is correct |
83 |
Correct |
16 ms |
1664 KB |
Output is correct |
84 |
Correct |
16 ms |
1664 KB |
Output is correct |
85 |
Correct |
16 ms |
1664 KB |
Output is correct |
86 |
Correct |
16 ms |
1664 KB |
Output is correct |
87 |
Correct |
15 ms |
1664 KB |
Output is correct |
88 |
Correct |
21 ms |
1664 KB |
Output is correct |
89 |
Correct |
16 ms |
1664 KB |
Output is correct |
90 |
Correct |
28 ms |
1664 KB |
Output is correct |
91 |
Correct |
24 ms |
1664 KB |
Output is correct |
92 |
Correct |
37 ms |
1784 KB |
Output is correct |
93 |
Correct |
45 ms |
1664 KB |
Output is correct |
94 |
Correct |
43 ms |
1664 KB |
Output is correct |
95 |
Correct |
44 ms |
1664 KB |
Output is correct |
96 |
Correct |
154 ms |
1536 KB |
Output is correct |
97 |
Correct |
345 ms |
1664 KB |
Output is correct |
98 |
Correct |
593 ms |
1784 KB |
Output is correct |
99 |
Correct |
529 ms |
1784 KB |
Output is correct |
100 |
Correct |
342 ms |
1400 KB |
Output is correct |