Submission #613937

# Submission time Handle Problem Language Result Execution time Memory
613937 2022-07-30T13:47:11 Z Richem Toy Train (IOI17_train) C++14
100 / 100
884 ms 25316 KB
#include <iostream>
#include <vector>
 
using namespace std;
 
const int MAX_SOMMET = 5042;
 
bool gagnant[MAX_SOMMET] = {0};
int qui[MAX_SOMMET];
bool recharge[MAX_SOMMET];
 
int nbSommet, nbArete;

vector<int> adj[MAX_SOMMET];

int nbSortant[MAX_SOMMET] = {0};

bool acces[MAX_SOMMET] = {0};
int premier = 1;

bool mAdj[MAX_SOMMET][MAX_SOMMET] = {0};

void dfs(int sommet, int type) {
    if((type == 1 && acces[sommet]) || (type == 2 && gagnant[sommet]))
        return;

    if(!premier && type == 1) 
        acces[sommet] = 1;
    if(type == 2)
        gagnant[sommet] = 1;

    premier = 0;

    for(auto voisin : adj[sommet]) {
        if(qui[voisin] == 1)
            dfs(voisin, type);
        else {
            nbSortant[voisin] -= mAdj[sommet][voisin];
            mAdj[sommet][voisin] = 0;
            if(nbSortant[voisin] == 0)
                dfs(voisin, type);
        }
    }
}

void resetSortant() {
    premier = 1;
    for(int sommet = 0; sommet < nbSommet; sommet++) {
        nbSortant[sommet] = 0;
        acces[sommet] = 0;
    }
    for(int sommet = 0; sommet < nbSommet; sommet++) {
        for(auto voisin : adj[sommet]) {
            nbSortant[voisin]++;
            mAdj[sommet][voisin] = 1;
        }
    }
}

vector<int> rep;

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    nbSommet = a.size();
    nbArete = u.size();
 
    for(int i = 0; i < nbSommet; i++) {
        gagnant[i] = 0;
        qui[i] = a[i];
        recharge[i] = r[i];
    }
 
    for(int id = 0; id < nbArete; id++)  {
        adj[v[id]].push_back(u[id]);
    }

    int nbPerdu = 0;

    resetSortant();

    do {
        nbPerdu = 0;
        resetSortant();

        for(int sommet = 0; sommet < nbSommet; sommet++) {
            if(recharge[sommet]) {
                dfs(sommet, 1);
                premier = 1;
            }
        }

        for(int sommet = 0; sommet < nbSommet; sommet++) {
            if(recharge[sommet] && !acces[sommet]) {
                nbPerdu++;
                recharge[sommet] = 0;
            }
        }
    } while(nbPerdu > 0);
    resetSortant();

    for(int sommet = 0; sommet < nbSommet; sommet++) {
        if(recharge[sommet]) 
            dfs(sommet, 2);
    }

    for(int sommet = 0; sommet < nbSommet; sommet++) {
        rep.push_back(gagnant[sommet]);
        //cout << gagnant[sommet] <<" ";
    }
    return rep;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 20980 KB Output is correct
2 Correct 17 ms 20956 KB Output is correct
3 Correct 15 ms 20920 KB Output is correct
4 Correct 17 ms 20828 KB Output is correct
5 Correct 14 ms 20696 KB Output is correct
6 Correct 16 ms 20276 KB Output is correct
7 Correct 13 ms 20192 KB Output is correct
8 Correct 13 ms 20120 KB Output is correct
9 Correct 12 ms 18772 KB Output is correct
10 Correct 11 ms 17108 KB Output is correct
11 Correct 13 ms 20964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 428 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 428 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 20804 KB Output is correct
2 Correct 248 ms 21768 KB Output is correct
3 Correct 364 ms 22612 KB Output is correct
4 Correct 20 ms 24148 KB Output is correct
5 Correct 22 ms 24752 KB Output is correct
6 Correct 21 ms 24276 KB Output is correct
7 Correct 16 ms 24868 KB Output is correct
8 Correct 17 ms 23344 KB Output is correct
9 Correct 14 ms 23280 KB Output is correct
10 Correct 16 ms 23252 KB Output is correct
11 Correct 14 ms 23356 KB Output is correct
12 Correct 15 ms 24508 KB Output is correct
13 Correct 16 ms 25300 KB Output is correct
14 Correct 18 ms 25300 KB Output is correct
15 Correct 16 ms 25156 KB Output is correct
16 Correct 17 ms 25152 KB Output is correct
17 Correct 21 ms 25128 KB Output is correct
18 Correct 470 ms 23944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22100 KB Output is correct
2 Correct 15 ms 21460 KB Output is correct
3 Correct 18 ms 21708 KB Output is correct
4 Correct 19 ms 24912 KB Output is correct
5 Correct 16 ms 23340 KB Output is correct
6 Correct 16 ms 23128 KB Output is correct
7 Correct 16 ms 23508 KB Output is correct
8 Correct 17 ms 23704 KB Output is correct
9 Correct 18 ms 24660 KB Output is correct
10 Correct 18 ms 25044 KB Output is correct
11 Correct 16 ms 25056 KB Output is correct
12 Correct 16 ms 24916 KB Output is correct
13 Correct 15 ms 24376 KB Output is correct
14 Correct 19 ms 23108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 24660 KB Output is correct
2 Correct 22 ms 25168 KB Output is correct
3 Correct 16 ms 24700 KB Output is correct
4 Correct 17 ms 23836 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 13 ms 16940 KB Output is correct
7 Correct 5 ms 3156 KB Output is correct
8 Correct 6 ms 3284 KB Output is correct
9 Correct 5 ms 3260 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 6 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 20980 KB Output is correct
2 Correct 17 ms 20956 KB Output is correct
3 Correct 15 ms 20920 KB Output is correct
4 Correct 17 ms 20828 KB Output is correct
5 Correct 14 ms 20696 KB Output is correct
6 Correct 16 ms 20276 KB Output is correct
7 Correct 13 ms 20192 KB Output is correct
8 Correct 13 ms 20120 KB Output is correct
9 Correct 12 ms 18772 KB Output is correct
10 Correct 11 ms 17108 KB Output is correct
11 Correct 13 ms 20964 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 428 KB Output is correct
21 Correct 1 ms 436 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 428 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 432 KB Output is correct
32 Correct 143 ms 20804 KB Output is correct
33 Correct 248 ms 21768 KB Output is correct
34 Correct 364 ms 22612 KB Output is correct
35 Correct 20 ms 24148 KB Output is correct
36 Correct 22 ms 24752 KB Output is correct
37 Correct 21 ms 24276 KB Output is correct
38 Correct 16 ms 24868 KB Output is correct
39 Correct 17 ms 23344 KB Output is correct
40 Correct 14 ms 23280 KB Output is correct
41 Correct 16 ms 23252 KB Output is correct
42 Correct 14 ms 23356 KB Output is correct
43 Correct 15 ms 24508 KB Output is correct
44 Correct 16 ms 25300 KB Output is correct
45 Correct 18 ms 25300 KB Output is correct
46 Correct 16 ms 25156 KB Output is correct
47 Correct 17 ms 25152 KB Output is correct
48 Correct 21 ms 25128 KB Output is correct
49 Correct 470 ms 23944 KB Output is correct
50 Correct 15 ms 22100 KB Output is correct
51 Correct 15 ms 21460 KB Output is correct
52 Correct 18 ms 21708 KB Output is correct
53 Correct 19 ms 24912 KB Output is correct
54 Correct 16 ms 23340 KB Output is correct
55 Correct 16 ms 23128 KB Output is correct
56 Correct 16 ms 23508 KB Output is correct
57 Correct 17 ms 23704 KB Output is correct
58 Correct 18 ms 24660 KB Output is correct
59 Correct 18 ms 25044 KB Output is correct
60 Correct 16 ms 25056 KB Output is correct
61 Correct 16 ms 24916 KB Output is correct
62 Correct 15 ms 24376 KB Output is correct
63 Correct 19 ms 23108 KB Output is correct
64 Correct 21 ms 24660 KB Output is correct
65 Correct 22 ms 25168 KB Output is correct
66 Correct 16 ms 24700 KB Output is correct
67 Correct 17 ms 23836 KB Output is correct
68 Correct 1 ms 696 KB Output is correct
69 Correct 13 ms 16940 KB Output is correct
70 Correct 5 ms 3156 KB Output is correct
71 Correct 6 ms 3284 KB Output is correct
72 Correct 5 ms 3260 KB Output is correct
73 Correct 2 ms 852 KB Output is correct
74 Correct 6 ms 4564 KB Output is correct
75 Correct 222 ms 21436 KB Output is correct
76 Correct 280 ms 21836 KB Output is correct
77 Correct 409 ms 22612 KB Output is correct
78 Correct 389 ms 22620 KB Output is correct
79 Correct 404 ms 22612 KB Output is correct
80 Correct 22 ms 23940 KB Output is correct
81 Correct 18 ms 23992 KB Output is correct
82 Correct 17 ms 24136 KB Output is correct
83 Correct 19 ms 24596 KB Output is correct
84 Correct 20 ms 24704 KB Output is correct
85 Correct 17 ms 22576 KB Output is correct
86 Correct 24 ms 24624 KB Output is correct
87 Correct 17 ms 22228 KB Output is correct
88 Correct 26 ms 24524 KB Output is correct
89 Correct 16 ms 23488 KB Output is correct
90 Correct 35 ms 24372 KB Output is correct
91 Correct 44 ms 24492 KB Output is correct
92 Correct 70 ms 24780 KB Output is correct
93 Correct 50 ms 23592 KB Output is correct
94 Correct 52 ms 24400 KB Output is correct
95 Correct 56 ms 24484 KB Output is correct
96 Correct 118 ms 23244 KB Output is correct
97 Correct 462 ms 25144 KB Output is correct
98 Correct 744 ms 25176 KB Output is correct
99 Correct 884 ms 25316 KB Output is correct
100 Correct 481 ms 23952 KB Output is correct