Submission #1047959

# Submission time Handle Problem Language Result Execution time Memory
1047959 2024-08-07T18:52:02 Z _8_8_ Toy Train (IOI17_train) C++17
100 / 100
1295 ms 2136 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5e3 + 12;

vector<int> g[N],gt[N];
vector<int> a,r;
int n;
vector<int> make(vector<int> t) {
    vector<bool> vis(n,false),gd(n,false),l(n,false);
    for(int i:t) {
        l[i] = 1;
    }
    vector<int> col(n,0),bf;
    for(int i:t) {
        for(int to:g[i]) {
            if(l[to]) { 
                col[i]++;
            }
        }
    }
    bf = col;
    queue<int> q;
    for(int i:t) {
        if(r[i]) {
            vis[i] = 1;
            q.push(i);
        }
    }
    while(!q.empty()) {
        int v = q.front();q.pop();
        gd[v] = 1;
        for(int to:gt[v]) {
            if(vis[to] || !l[to]) continue;
            if(a[to] == 1) {
                q.push(to);
                vis[to] = 1;
            } else {
                col[to]--;
                if(!col[to]) {
                    q.push(to);
                    vis[to] = 1;
                }
            }
        }
    }
    vis.assign(n,false);
    col = bf;
    for(int i:t) {
        if(!gd[i]) {
            q.push(i);
            vis[i] = 1;
        }
    }
    while(!q.empty()) {
        int v = q.front();q.pop();
        gd[v] = 0;
        for(int to:gt[v]) {
            if(!l[to] || vis[to])continue;
            if(!a[to]) {
                q.push(to);
                vis[to] = 1;
            } else {
                col[to]--;
                if(!col[to]) {
                    q.push(to);
                    vis[to] = 1;
                }
            }
        }
    }
    vector<int> ret;
    for(int i:t) {
        if(gd[i]) ret.push_back(i);
    }
    return ret;
}
vector<int> who_wins(vector<int> a_, vector<int> r_, vector<int> u, vector<int> v) {
    a = a_;
    r = r_;
    n = (int)a.size();
    for(int i = 0;i < (int)u.size();i++) {
        g[u[i]].push_back(v[i]);
        gt[v[i]].push_back(u[i]);
    }
    vector<int> f(n),res(n,0);
    iota(f.begin(),f.end(),0);
    // f = make(f);
    for(int i = 0;i < n;i++) {
        f = make(f);
    }
    for(int i:f) {
        res[i] = 1;
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 172 ms 1368 KB Output is correct
2 Correct 167 ms 1368 KB Output is correct
3 Correct 198 ms 1400 KB Output is correct
4 Correct 202 ms 1404 KB Output is correct
5 Correct 159 ms 1372 KB Output is correct
6 Correct 177 ms 1396 KB Output is correct
7 Correct 50 ms 1372 KB Output is correct
8 Correct 297 ms 1452 KB Output is correct
9 Correct 198 ms 1388 KB Output is correct
10 Correct 179 ms 1368 KB Output is correct
11 Correct 147 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 672 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 676 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1884 KB Output is correct
2 Correct 104 ms 1984 KB Output is correct
3 Correct 104 ms 1960 KB Output is correct
4 Correct 1045 ms 2128 KB Output is correct
5 Correct 685 ms 1880 KB Output is correct
6 Correct 24 ms 1624 KB Output is correct
7 Correct 824 ms 1884 KB Output is correct
8 Correct 317 ms 1628 KB Output is correct
9 Correct 19 ms 1800 KB Output is correct
10 Correct 478 ms 1884 KB Output is correct
11 Correct 402 ms 1624 KB Output is correct
12 Correct 13 ms 1628 KB Output is correct
13 Correct 886 ms 1928 KB Output is correct
14 Correct 839 ms 1932 KB Output is correct
15 Correct 885 ms 2136 KB Output is correct
16 Correct 852 ms 1884 KB Output is correct
17 Correct 935 ms 1936 KB Output is correct
18 Correct 110 ms 1564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 1700 KB Output is correct
2 Correct 626 ms 1880 KB Output is correct
3 Correct 35 ms 1628 KB Output is correct
4 Correct 9 ms 1628 KB Output is correct
5 Correct 434 ms 1628 KB Output is correct
6 Correct 900 ms 1624 KB Output is correct
7 Correct 810 ms 1804 KB Output is correct
8 Correct 19 ms 1628 KB Output is correct
9 Correct 326 ms 1744 KB Output is correct
10 Correct 959 ms 1932 KB Output is correct
11 Correct 727 ms 1932 KB Output is correct
12 Correct 965 ms 1932 KB Output is correct
13 Correct 394 ms 1840 KB Output is correct
14 Correct 774 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 1628 KB Output is correct
2 Correct 1024 ms 1884 KB Output is correct
3 Correct 1263 ms 1860 KB Output is correct
4 Correct 1121 ms 1628 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 20 ms 1372 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 16 ms 1368 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 37 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 1368 KB Output is correct
2 Correct 167 ms 1368 KB Output is correct
3 Correct 198 ms 1400 KB Output is correct
4 Correct 202 ms 1404 KB Output is correct
5 Correct 159 ms 1372 KB Output is correct
6 Correct 177 ms 1396 KB Output is correct
7 Correct 50 ms 1372 KB Output is correct
8 Correct 297 ms 1452 KB Output is correct
9 Correct 198 ms 1388 KB Output is correct
10 Correct 179 ms 1368 KB Output is correct
11 Correct 147 ms 1368 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 672 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 676 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 55 ms 1884 KB Output is correct
33 Correct 104 ms 1984 KB Output is correct
34 Correct 104 ms 1960 KB Output is correct
35 Correct 1045 ms 2128 KB Output is correct
36 Correct 685 ms 1880 KB Output is correct
37 Correct 24 ms 1624 KB Output is correct
38 Correct 824 ms 1884 KB Output is correct
39 Correct 317 ms 1628 KB Output is correct
40 Correct 19 ms 1800 KB Output is correct
41 Correct 478 ms 1884 KB Output is correct
42 Correct 402 ms 1624 KB Output is correct
43 Correct 13 ms 1628 KB Output is correct
44 Correct 886 ms 1928 KB Output is correct
45 Correct 839 ms 1932 KB Output is correct
46 Correct 885 ms 2136 KB Output is correct
47 Correct 852 ms 1884 KB Output is correct
48 Correct 935 ms 1936 KB Output is correct
49 Correct 110 ms 1564 KB Output is correct
50 Correct 424 ms 1700 KB Output is correct
51 Correct 626 ms 1880 KB Output is correct
52 Correct 35 ms 1628 KB Output is correct
53 Correct 9 ms 1628 KB Output is correct
54 Correct 434 ms 1628 KB Output is correct
55 Correct 900 ms 1624 KB Output is correct
56 Correct 810 ms 1804 KB Output is correct
57 Correct 19 ms 1628 KB Output is correct
58 Correct 326 ms 1744 KB Output is correct
59 Correct 959 ms 1932 KB Output is correct
60 Correct 727 ms 1932 KB Output is correct
61 Correct 965 ms 1932 KB Output is correct
62 Correct 394 ms 1840 KB Output is correct
63 Correct 774 ms 1744 KB Output is correct
64 Correct 451 ms 1628 KB Output is correct
65 Correct 1024 ms 1884 KB Output is correct
66 Correct 1263 ms 1860 KB Output is correct
67 Correct 1121 ms 1628 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 7 ms 1372 KB Output is correct
70 Correct 20 ms 1372 KB Output is correct
71 Correct 3 ms 1372 KB Output is correct
72 Correct 16 ms 1368 KB Output is correct
73 Correct 1 ms 860 KB Output is correct
74 Correct 37 ms 1116 KB Output is correct
75 Correct 82 ms 2136 KB Output is correct
76 Correct 102 ms 1884 KB Output is correct
77 Correct 122 ms 1880 KB Output is correct
78 Correct 123 ms 1880 KB Output is correct
79 Correct 122 ms 1880 KB Output is correct
80 Correct 1295 ms 1880 KB Output is correct
81 Correct 164 ms 1628 KB Output is correct
82 Correct 369 ms 1844 KB Output is correct
83 Correct 762 ms 1884 KB Output is correct
84 Correct 313 ms 1884 KB Output is correct
85 Correct 11 ms 1624 KB Output is correct
86 Correct 238 ms 1884 KB Output is correct
87 Correct 9 ms 1624 KB Output is correct
88 Correct 96 ms 1884 KB Output is correct
89 Correct 251 ms 1876 KB Output is correct
90 Correct 13 ms 1884 KB Output is correct
91 Correct 57 ms 1904 KB Output is correct
92 Correct 204 ms 1928 KB Output is correct
93 Correct 180 ms 1884 KB Output is correct
94 Correct 99 ms 1880 KB Output is correct
95 Correct 223 ms 1880 KB Output is correct
96 Correct 737 ms 1876 KB Output is correct
97 Correct 195 ms 1944 KB Output is correct
98 Correct 225 ms 1712 KB Output is correct
99 Correct 186 ms 1884 KB Output is correct
100 Correct 103 ms 1368 KB Output is correct