Submission #116999

# Submission time Handle Problem Language Result Execution time Memory
116999 2019-06-14T12:03:11 Z zubec Toy Train (IOI17_train) C++14
100 / 100
948 ms 1652 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;


vector <int> gg[5010];

int kol[5010];
bool used[5010];

int n, clr[5010], chrg[5010];

bool delt[5010];

vector <pair<int, int> > rebr;

queue <int> q;

void cler(){
    for (int i = 0; i < n; i++){
        used[i] = 0;
        kol[i] = 0;
    }
    for (int i = 0; i < rebr.size(); i++){
        int u = rebr[i].first, v = rebr[i].second;
        if (!delt[u] && !delt[v])
            ++kol[u];
    }
}


void f(int c){
    cler();
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if (used[v])
            continue;
        used[v] = 1;
        for (int j = 0; j < gg[v].size(); j++){
            int to = gg[v][j];
            if (delt[to])
                continue;
            --kol[to];
            if (used[to])
                continue;
            if (clr[to] == c){
                q.push(to);
            } else
            if (kol[to] == 0){
                q.push(to);
            }
        }
    }
}

vector <int> vec;
bool solve(){
    for (int i = 0; i < vec.size(); i++){
        if (chrg[vec[i]])
            q.push(vec[i]);
    }
    f(0);
    for (int i = 0; i < vec.size(); i++){
        if (!used[vec[i]])
            q.push(vec[i]);
    }
    f(1);
    bool bb = 0;
    for (int i = vec.size()-1; i >= 0; i--){
        if (used[vec[i]]){
            bb = 1;
            delt[vec[i]] = 1;
            swap(vec[i], vec.back());
            vec.pop_back();
        }
    }
    return bb;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
    vector <int> ansvec;
    rebr.clear();
    n = a.size();
    for (int i = 0; i < n; i++){
        gg[i].clear();
        delt[i] = 0;
        clr[i] = a[i]^1;
        chrg[i] = r[i];
    }
    for (int i = 0; i < u.size(); i++){
        gg[v[i]].push_back(u[i]);
        rebr.push_back({u[i], v[i]});
    }

    for (int i = 0; i < n; i++){
        vec.push_back(i);
    }
    while(solve()){

    }
    ansvec.resize(n);
    for (int i = 0; i < vec.size(); i++){
        ansvec[vec[i]] = 1;
    }

    return ansvec;
}

/**

2 4
0 1
1 0

0 0
0 1
1 0
1 1

*/

Compilation message

train.cpp: In function 'void cler()':
train.cpp:24:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < rebr.size(); i++){
                     ~~^~~~~~~~~~~~~
train.cpp: In function 'void f(int)':
train.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < gg[v].size(); j++){
                         ~~^~~~~~~~~~~~~~
train.cpp: In function 'bool solve()':
train.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
train.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:91:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < u.size(); i++){
                     ~~^~~~~~~~~~
train.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 896 KB Output is correct
2 Correct 7 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 7 ms 1024 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 6 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 7 ms 1152 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 6 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1408 KB Output is correct
2 Correct 173 ms 1652 KB Output is correct
3 Correct 260 ms 1652 KB Output is correct
4 Correct 10 ms 1536 KB Output is correct
5 Correct 11 ms 1536 KB Output is correct
6 Correct 11 ms 1556 KB Output is correct
7 Correct 9 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 8 ms 1536 KB Output is correct
10 Correct 9 ms 1536 KB Output is correct
11 Correct 9 ms 1536 KB Output is correct
12 Correct 8 ms 1536 KB Output is correct
13 Correct 9 ms 1536 KB Output is correct
14 Correct 9 ms 1536 KB Output is correct
15 Correct 12 ms 1536 KB Output is correct
16 Correct 13 ms 1536 KB Output is correct
17 Correct 10 ms 1536 KB Output is correct
18 Correct 408 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1148 KB Output is correct
2 Correct 10 ms 1504 KB Output is correct
3 Correct 9 ms 1536 KB Output is correct
4 Correct 11 ms 1536 KB Output is correct
5 Correct 9 ms 1536 KB Output is correct
6 Correct 9 ms 1536 KB Output is correct
7 Correct 11 ms 1536 KB Output is correct
8 Correct 10 ms 1536 KB Output is correct
9 Correct 11 ms 1536 KB Output is correct
10 Correct 13 ms 1536 KB Output is correct
11 Correct 10 ms 1536 KB Output is correct
12 Correct 11 ms 1528 KB Output is correct
13 Correct 10 ms 1536 KB Output is correct
14 Correct 10 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1280 KB Output is correct
2 Correct 10 ms 1496 KB Output is correct
3 Correct 11 ms 1536 KB Output is correct
4 Correct 10 ms 1536 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 7 ms 1024 KB Output is correct
7 Correct 7 ms 1280 KB Output is correct
8 Correct 7 ms 1408 KB Output is correct
9 Correct 7 ms 1280 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 9 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 896 KB Output is correct
2 Correct 7 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 7 ms 1024 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 6 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 7 ms 1152 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 6 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 93 ms 1408 KB Output is correct
33 Correct 173 ms 1652 KB Output is correct
34 Correct 260 ms 1652 KB Output is correct
35 Correct 10 ms 1536 KB Output is correct
36 Correct 11 ms 1536 KB Output is correct
37 Correct 11 ms 1556 KB Output is correct
38 Correct 9 ms 1536 KB Output is correct
39 Correct 9 ms 1536 KB Output is correct
40 Correct 8 ms 1536 KB Output is correct
41 Correct 9 ms 1536 KB Output is correct
42 Correct 9 ms 1536 KB Output is correct
43 Correct 8 ms 1536 KB Output is correct
44 Correct 9 ms 1536 KB Output is correct
45 Correct 9 ms 1536 KB Output is correct
46 Correct 12 ms 1536 KB Output is correct
47 Correct 13 ms 1536 KB Output is correct
48 Correct 10 ms 1536 KB Output is correct
49 Correct 408 ms 1220 KB Output is correct
50 Correct 8 ms 1148 KB Output is correct
51 Correct 10 ms 1504 KB Output is correct
52 Correct 9 ms 1536 KB Output is correct
53 Correct 11 ms 1536 KB Output is correct
54 Correct 9 ms 1536 KB Output is correct
55 Correct 9 ms 1536 KB Output is correct
56 Correct 11 ms 1536 KB Output is correct
57 Correct 10 ms 1536 KB Output is correct
58 Correct 11 ms 1536 KB Output is correct
59 Correct 13 ms 1536 KB Output is correct
60 Correct 10 ms 1536 KB Output is correct
61 Correct 11 ms 1528 KB Output is correct
62 Correct 10 ms 1536 KB Output is correct
63 Correct 10 ms 1484 KB Output is correct
64 Correct 10 ms 1280 KB Output is correct
65 Correct 10 ms 1496 KB Output is correct
66 Correct 11 ms 1536 KB Output is correct
67 Correct 10 ms 1536 KB Output is correct
68 Correct 4 ms 512 KB Output is correct
69 Correct 7 ms 1024 KB Output is correct
70 Correct 7 ms 1280 KB Output is correct
71 Correct 7 ms 1408 KB Output is correct
72 Correct 7 ms 1280 KB Output is correct
73 Correct 6 ms 640 KB Output is correct
74 Correct 9 ms 1280 KB Output is correct
75 Correct 167 ms 1624 KB Output is correct
76 Correct 178 ms 1652 KB Output is correct
77 Correct 257 ms 1624 KB Output is correct
78 Correct 268 ms 1652 KB Output is correct
79 Correct 240 ms 1536 KB Output is correct
80 Correct 9 ms 1536 KB Output is correct
81 Correct 10 ms 1536 KB Output is correct
82 Correct 11 ms 1536 KB Output is correct
83 Correct 10 ms 1536 KB Output is correct
84 Correct 11 ms 1536 KB Output is correct
85 Correct 10 ms 1520 KB Output is correct
86 Correct 11 ms 1536 KB Output is correct
87 Correct 9 ms 1536 KB Output is correct
88 Correct 14 ms 1536 KB Output is correct
89 Correct 10 ms 1564 KB Output is correct
90 Correct 17 ms 1536 KB Output is correct
91 Correct 18 ms 1536 KB Output is correct
92 Correct 32 ms 1536 KB Output is correct
93 Correct 28 ms 1536 KB Output is correct
94 Correct 30 ms 1648 KB Output is correct
95 Correct 34 ms 1536 KB Output is correct
96 Correct 85 ms 1536 KB Output is correct
97 Correct 565 ms 1576 KB Output is correct
98 Correct 817 ms 1652 KB Output is correct
99 Correct 948 ms 1652 KB Output is correct
100 Correct 430 ms 1152 KB Output is correct