Submission #372478

# Submission time Handle Problem Language Result Execution time Memory
372478 2021-02-28T09:55:50 Z doowey Toy Train (IOI17_train) C++14
100 / 100
1568 ms 1772 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair

const int N = 5010;
bool ban[N];
bool inq[N];
int n, m;
vector<int> a;
vector<int> r;
vector<int> u;
vector<int> v;

vector<int> in[N];
int deg[N];

vector<int> f(int bit, vector<int> init){
    for(int i = 0 ; i < n; i ++ ){
        inq[i]=false;
        in[i].clear();
        deg[i]=0;
    }
    queue<int> ads;
    for(auto x : init){
        ads.push(x);
        inq[x]=true;
    }
    for(int i =0  ; i < m ; i ++ ){
        if(!ban[u[i]] && !ban[v[i]]){
            in[v[i]].push_back(u[i]);
            deg[u[i]] ++ ;
        }
    }
    for(int i = 0 ; i < n; i ++ ){
        if(a[i] == bit) deg[i]=1;
    }
    int node;
    while(!ads.empty()){
        node = ads.front();
        ads.pop();
        for(auto x : in[node]){
            if(inq[x]) continue;
            deg[x]--;
            if(deg[x] == 0){
                ads.push(x);
                init.push_back(x);
                inq[x]=true;
            }
        }
    }
    return init;
}

vector<int> sol;
int has[N];

vector<int> who_wins(vector<int> _a, vector<int> _r, vector<int> _u, vector<int> _v) {
    a = _a;
    r = _r;
    u = _u;
    v = _v;
    n = _a.size();
    m = u.size();
    bool ok;
    sol.resize(n);
    int rem = 0;
    while(1){
        ok = false;
        vector<int> start;
        rem = 0;
        for(int i = 0 ; i < n; i ++ ){
            if(r[i] && !ban[i]) start.push_back(i);
            if(!ban[i]){
                rem ++ ;
            }
            has[i]=false;
        }
        if(start.empty()){
            for(int i = 0 ; i < n; i ++ ){
                if(!ban[i]){
                    ban[i]=true;
                    sol[i]=0;
                }
            }
            break;
        }
        start = f(1, start);
        for(auto x : start) has[x]=true;
        if(start.size() == rem){
            for(int i = 0 ; i < n; i ++ ){
                if(!ban[i]){
                    sol[i]=1;
                    ban[i]=true;
                }
            }
            break;
        }
        vector<int> nw;
        for(int i = 0 ; i < n; i ++ ){
            if(!ban[i] && !has[i]){
                nw.push_back(i);
            }
        }
        nw = f(0, nw);
        for(auto x : nw){
            sol[x]=0;
            ban[x]=true;
        }
    }
	return sol;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:97:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |         if(start.size() == rem){
      |            ~~~~~~~~~~~~~^~~~~~
train.cpp:72:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   72 |     bool ok;
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1132 KB Output is correct
2 Correct 8 ms 1132 KB Output is correct
3 Correct 7 ms 1132 KB Output is correct
4 Correct 7 ms 1132 KB Output is correct
5 Correct 6 ms 1132 KB Output is correct
6 Correct 6 ms 1132 KB Output is correct
7 Correct 5 ms 1132 KB Output is correct
8 Correct 7 ms 1132 KB Output is correct
9 Correct 6 ms 1132 KB Output is correct
10 Correct 5 ms 1004 KB Output is correct
11 Correct 5 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 6 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 1644 KB Output is correct
2 Correct 623 ms 1772 KB Output is correct
3 Correct 842 ms 1644 KB Output is correct
4 Correct 9 ms 1644 KB Output is correct
5 Correct 11 ms 1516 KB Output is correct
6 Correct 12 ms 1644 KB Output is correct
7 Correct 8 ms 1644 KB Output is correct
8 Correct 11 ms 1644 KB Output is correct
9 Correct 8 ms 1516 KB Output is correct
10 Correct 9 ms 1516 KB Output is correct
11 Correct 9 ms 1516 KB Output is correct
12 Correct 8 ms 1516 KB Output is correct
13 Correct 8 ms 1644 KB Output is correct
14 Correct 8 ms 1644 KB Output is correct
15 Correct 8 ms 1644 KB Output is correct
16 Correct 8 ms 1644 KB Output is correct
17 Correct 8 ms 1644 KB Output is correct
18 Correct 940 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1388 KB Output is correct
2 Correct 8 ms 1516 KB Output is correct
3 Correct 9 ms 1644 KB Output is correct
4 Correct 9 ms 1644 KB Output is correct
5 Correct 9 ms 1644 KB Output is correct
6 Correct 9 ms 1516 KB Output is correct
7 Correct 9 ms 1516 KB Output is correct
8 Correct 8 ms 1516 KB Output is correct
9 Correct 8 ms 1516 KB Output is correct
10 Correct 8 ms 1644 KB Output is correct
11 Correct 8 ms 1644 KB Output is correct
12 Correct 8 ms 1644 KB Output is correct
13 Correct 9 ms 1516 KB Output is correct
14 Correct 8 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1644 KB Output is correct
2 Correct 8 ms 1644 KB Output is correct
3 Correct 9 ms 1516 KB Output is correct
4 Correct 8 ms 1516 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 5 ms 1132 KB Output is correct
7 Correct 6 ms 1132 KB Output is correct
8 Correct 6 ms 1260 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 6 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1132 KB Output is correct
2 Correct 8 ms 1132 KB Output is correct
3 Correct 7 ms 1132 KB Output is correct
4 Correct 7 ms 1132 KB Output is correct
5 Correct 6 ms 1132 KB Output is correct
6 Correct 6 ms 1132 KB Output is correct
7 Correct 5 ms 1132 KB Output is correct
8 Correct 7 ms 1132 KB Output is correct
9 Correct 6 ms 1132 KB Output is correct
10 Correct 5 ms 1004 KB Output is correct
11 Correct 5 ms 1004 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 6 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 328 ms 1644 KB Output is correct
33 Correct 623 ms 1772 KB Output is correct
34 Correct 842 ms 1644 KB Output is correct
35 Correct 9 ms 1644 KB Output is correct
36 Correct 11 ms 1516 KB Output is correct
37 Correct 12 ms 1644 KB Output is correct
38 Correct 8 ms 1644 KB Output is correct
39 Correct 11 ms 1644 KB Output is correct
40 Correct 8 ms 1516 KB Output is correct
41 Correct 9 ms 1516 KB Output is correct
42 Correct 9 ms 1516 KB Output is correct
43 Correct 8 ms 1516 KB Output is correct
44 Correct 8 ms 1644 KB Output is correct
45 Correct 8 ms 1644 KB Output is correct
46 Correct 8 ms 1644 KB Output is correct
47 Correct 8 ms 1644 KB Output is correct
48 Correct 8 ms 1644 KB Output is correct
49 Correct 940 ms 1256 KB Output is correct
50 Correct 8 ms 1388 KB Output is correct
51 Correct 8 ms 1516 KB Output is correct
52 Correct 9 ms 1644 KB Output is correct
53 Correct 9 ms 1644 KB Output is correct
54 Correct 9 ms 1644 KB Output is correct
55 Correct 9 ms 1516 KB Output is correct
56 Correct 9 ms 1516 KB Output is correct
57 Correct 8 ms 1516 KB Output is correct
58 Correct 8 ms 1516 KB Output is correct
59 Correct 8 ms 1644 KB Output is correct
60 Correct 8 ms 1644 KB Output is correct
61 Correct 8 ms 1644 KB Output is correct
62 Correct 9 ms 1516 KB Output is correct
63 Correct 8 ms 1516 KB Output is correct
64 Correct 9 ms 1644 KB Output is correct
65 Correct 8 ms 1644 KB Output is correct
66 Correct 9 ms 1516 KB Output is correct
67 Correct 8 ms 1516 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 5 ms 1132 KB Output is correct
70 Correct 6 ms 1132 KB Output is correct
71 Correct 6 ms 1260 KB Output is correct
72 Correct 6 ms 1260 KB Output is correct
73 Correct 2 ms 640 KB Output is correct
74 Correct 6 ms 1132 KB Output is correct
75 Correct 548 ms 1592 KB Output is correct
76 Correct 683 ms 1772 KB Output is correct
77 Correct 953 ms 1772 KB Output is correct
78 Correct 937 ms 1644 KB Output is correct
79 Correct 944 ms 1644 KB Output is correct
80 Correct 10 ms 1772 KB Output is correct
81 Correct 9 ms 1644 KB Output is correct
82 Correct 11 ms 1516 KB Output is correct
83 Correct 11 ms 1644 KB Output is correct
84 Correct 12 ms 1644 KB Output is correct
85 Correct 10 ms 1516 KB Output is correct
86 Correct 17 ms 1644 KB Output is correct
87 Correct 11 ms 1644 KB Output is correct
88 Correct 18 ms 1644 KB Output is correct
89 Correct 12 ms 1644 KB Output is correct
90 Correct 26 ms 1516 KB Output is correct
91 Correct 25 ms 1644 KB Output is correct
92 Correct 54 ms 1644 KB Output is correct
93 Correct 52 ms 1644 KB Output is correct
94 Correct 50 ms 1644 KB Output is correct
95 Correct 60 ms 1644 KB Output is correct
96 Correct 197 ms 1772 KB Output is correct
97 Correct 979 ms 1644 KB Output is correct
98 Correct 1466 ms 1612 KB Output is correct
99 Correct 1568 ms 1644 KB Output is correct
100 Correct 954 ms 1256 KB Output is correct