Submission #423351

# Submission time Handle Problem Language Result Execution time Memory
423351 2021-06-11T02:39:07 Z timmyfeng Toy Train (IOI17_train) C++17
37 / 100
2000 ms 1736 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5000;

vector<int> to[N], from[N], a;
int degree[N], n, m;

void bfs(vector<int> &visited, int player) {
    queue<int> que;
    for (int i = 0; i < n; ++i) {
        degree[i] = 0;
        if (visited[i] == 1) {
            que.push(i);
        }
    }

    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto c : from[u]) {
            if (visited[c] == 0) {
                if (a[c] == player || ++degree[c] == (int) to[c].size()) {
                    visited[c] = 1;
                    que.push(c);
                }
            }
        }
    }
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    n = a.size(), m = u.size(), ::a = a;

    for (int i = 0; i < m; ++i) {
        to[u[i]].push_back(v[i]);
        from[v[i]].push_back(u[i]);
    }

    for (int i = 0; i < n; ++i) {
        vector<int> visited = r;
        bfs(visited, 1);
        for (auto &i : visited) {
            i = 1 - i;
        }

        bfs(visited, 0);
        for (int i = 0; i < n; ++i) {
            if (visited[i] == 1) {
                r[i] = 0;
            }
        }
    }

    vector<int> ans = r;
    bfs(ans, 1);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 747 ms 1100 KB Output is correct
2 Correct 758 ms 1160 KB Output is correct
3 Correct 749 ms 1220 KB Output is correct
4 Correct 716 ms 1228 KB Output is correct
5 Correct 751 ms 1156 KB Output is correct
6 Correct 756 ms 1160 KB Output is correct
7 Correct 574 ms 1100 KB Output is correct
8 Correct 797 ms 1152 KB Output is correct
9 Correct 777 ms 1136 KB Output is correct
10 Correct 765 ms 1180 KB Output is correct
11 Correct 584 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 536 KB Output is correct
2 Correct 1 ms 536 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 460 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 460 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 613 ms 1664 KB Output is correct
2 Correct 657 ms 1648 KB Output is correct
3 Correct 709 ms 1640 KB Output is correct
4 Correct 1133 ms 1612 KB Output is correct
5 Correct 1449 ms 1688 KB Output is correct
6 Correct 782 ms 1564 KB Output is correct
7 Correct 1031 ms 1584 KB Output is correct
8 Correct 1538 ms 1592 KB Output is correct
9 Correct 817 ms 1564 KB Output is correct
10 Correct 1432 ms 1544 KB Output is correct
11 Correct 1567 ms 1532 KB Output is correct
12 Correct 772 ms 1496 KB Output is correct
13 Correct 1145 ms 1612 KB Output is correct
14 Correct 1189 ms 1608 KB Output is correct
15 Correct 1111 ms 1608 KB Output is correct
16 Correct 1170 ms 1612 KB Output is correct
17 Correct 1158 ms 1612 KB Output is correct
18 Correct 607 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 749 ms 1356 KB Output is correct
2 Correct 1473 ms 1464 KB Output is correct
3 Correct 810 ms 1588 KB Output is correct
4 Correct 726 ms 1612 KB Output is correct
5 Correct 1369 ms 1584 KB Output is correct
6 Correct 1571 ms 1568 KB Output is correct
7 Correct 1510 ms 1568 KB Output is correct
8 Correct 733 ms 1548 KB Output is correct
9 Correct 1179 ms 1500 KB Output is correct
10 Correct 1243 ms 1612 KB Output is correct
11 Correct 926 ms 1612 KB Output is correct
12 Correct 1312 ms 1680 KB Output is correct
13 Correct 1383 ms 1588 KB Output is correct
14 Correct 1473 ms 1504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1818 ms 1592 KB Output is correct
2 Correct 1496 ms 1612 KB Output is correct
3 Execution timed out 2016 ms 1736 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 747 ms 1100 KB Output is correct
2 Correct 758 ms 1160 KB Output is correct
3 Correct 749 ms 1220 KB Output is correct
4 Correct 716 ms 1228 KB Output is correct
5 Correct 751 ms 1156 KB Output is correct
6 Correct 756 ms 1160 KB Output is correct
7 Correct 574 ms 1100 KB Output is correct
8 Correct 797 ms 1152 KB Output is correct
9 Correct 777 ms 1136 KB Output is correct
10 Correct 765 ms 1180 KB Output is correct
11 Correct 584 ms 1128 KB Output is correct
12 Correct 1 ms 536 KB Output is correct
13 Correct 1 ms 536 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
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 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 613 ms 1664 KB Output is correct
33 Correct 657 ms 1648 KB Output is correct
34 Correct 709 ms 1640 KB Output is correct
35 Correct 1133 ms 1612 KB Output is correct
36 Correct 1449 ms 1688 KB Output is correct
37 Correct 782 ms 1564 KB Output is correct
38 Correct 1031 ms 1584 KB Output is correct
39 Correct 1538 ms 1592 KB Output is correct
40 Correct 817 ms 1564 KB Output is correct
41 Correct 1432 ms 1544 KB Output is correct
42 Correct 1567 ms 1532 KB Output is correct
43 Correct 772 ms 1496 KB Output is correct
44 Correct 1145 ms 1612 KB Output is correct
45 Correct 1189 ms 1608 KB Output is correct
46 Correct 1111 ms 1608 KB Output is correct
47 Correct 1170 ms 1612 KB Output is correct
48 Correct 1158 ms 1612 KB Output is correct
49 Correct 607 ms 1352 KB Output is correct
50 Correct 749 ms 1356 KB Output is correct
51 Correct 1473 ms 1464 KB Output is correct
52 Correct 810 ms 1588 KB Output is correct
53 Correct 726 ms 1612 KB Output is correct
54 Correct 1369 ms 1584 KB Output is correct
55 Correct 1571 ms 1568 KB Output is correct
56 Correct 1510 ms 1568 KB Output is correct
57 Correct 733 ms 1548 KB Output is correct
58 Correct 1179 ms 1500 KB Output is correct
59 Correct 1243 ms 1612 KB Output is correct
60 Correct 926 ms 1612 KB Output is correct
61 Correct 1312 ms 1680 KB Output is correct
62 Correct 1383 ms 1588 KB Output is correct
63 Correct 1473 ms 1504 KB Output is correct
64 Correct 1818 ms 1592 KB Output is correct
65 Correct 1496 ms 1612 KB Output is correct
66 Execution timed out 2016 ms 1736 KB Time limit exceeded
67 Halted 0 ms 0 KB -