Submission #602988

# Submission time Handle Problem Language Result Execution time Memory
602988 2022-07-23T13:46:40 Z mosiashvililuka Toy Train (IOI17_train) C++14
100 / 100
619 ms 3484 KB
#include<bits/stdc++.h>
#include "train.h"
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[5009],g[5009],k[5009],boA[5009],boB[5009],bo[5009],p[5009],pi;
vector <int> S,X,ans;
set <int> v[5009],V[5009];
void adA(int q){
    for(set <int>::iterator it=V[q].begin(); it!=V[q].end(); it++){
        //if(bo[(*it)]==1) continue;
        if(boA[(*it)]==1) continue;
        if(f[(*it)]==1){
            boA[(*it)]=1;
            S.push_back((*it));
        }else{
            k[(*it)]--;
            if(k[(*it)]==0){
                boA[(*it)]=1;
                S.push_back((*it));
            }
        }
    }
}
void adB(int q){
    for(set <int>::iterator it=V[q].begin(); it!=V[q].end(); it++){
        //if(bo[(*it)]==1) continue;
        if(boB[(*it)]==1) continue;
        if(f[(*it)]==0){
            boB[(*it)]=1;
            X.push_back((*it));
        }else{
            k[(*it)]--;
            if(k[(*it)]==0){
                boB[(*it)]=1;
                X.push_back((*it));
            }
        }
    }
}
vector<int> who_wins(std::vector<int> Aa, std::vector<int> Rr, std::vector<int> Uu, std::vector<int> Vv) {
    a=Aa.size();b=Uu.size();
    for(i=1; i<=a; i++) f[i]=Aa[i-1];
    for(i=1; i<=a; i++) g[i]=Rr[i-1];
    for(i=0; i<b; i++){
        Uu[i]++;Vv[i]++;
        v[Uu[i]].insert(Vv[i]);
        V[Vv[i]].insert(Uu[i]);
    }
    while(1){
    //
    S.clear();X.clear();
    for(i=1; i<=a; i++){
        /*if(bo[i]==0){
            boA[i]=boB[i]=0;
        }else{
            boA[i]=boB[i]=1;
        }*/
        boA[i]=boB[i]=0;
    }
    for(i=1; i<=a; i++){
        if(bo[i]==1) continue;
        k[i]=v[i].size();
    }
    for(i=1; i<=a; i++){
        if(bo[i]==1) continue;
        if(g[i]==1){
            S.push_back(i);boA[i]=1;
        }
    }
    for(ii=0; ii<S.size(); ii++){
        adA(S[ii]);
    }
    for(i=1; i<=a; i++){
        if(bo[i]==1) continue;
        if(boA[i]==0){
            X.push_back(i);boB[i]=1;
        }
    }
    for(i=1; i<=a; i++){
        if(bo[i]==1) continue;
        k[i]=v[i].size();
    }
    for(ii=0; ii<X.size(); ii++){
        adB(X[ii]);
    }
    if(X.size()==0){
        for(i=1; i<=a; i++){
            if(bo[i]==0) ans.push_back(1); else ans.push_back(0);
        }
        return ans;
    }
    for(ii=0; ii<X.size(); ii++){
        i=X[ii];
        for(set <int>::iterator it=v[i].begin(); it!=v[i].end(); it++){
            V[(*it)].erase(V[(*it)].find(i));
        }
        v[i].clear();
        for(set <int>::iterator it=V[i].begin(); it!=V[i].end(); it++){
            v[(*it)].erase(v[(*it)].find(i));
        }
        V[i].clear();
    }
    for(ii=0; ii<X.size(); ii++){
        i=X[ii];
        bo[i]=1;
    }
    //
    }
}

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:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(ii=0; ii<S.size(); ii++){
      |               ~~^~~~~~~~~
train.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(ii=0; ii<X.size(); ii++){
      |               ~~^~~~~~~~~
train.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(ii=0; ii<X.size(); ii++){
      |               ~~^~~~~~~~~
train.cpp:102:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(ii=0; ii<X.size(); ii++){
      |               ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 6 ms 1876 KB Output is correct
3 Correct 6 ms 1912 KB Output is correct
4 Correct 5 ms 1844 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 8 ms 1800 KB Output is correct
8 Correct 7 ms 1812 KB Output is correct
9 Correct 6 ms 1748 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 4 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 772 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 776 KB Output is correct
14 Correct 1 ms 776 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 3408 KB Output is correct
2 Correct 330 ms 3416 KB Output is correct
3 Correct 446 ms 3404 KB Output is correct
4 Correct 13 ms 3444 KB Output is correct
5 Correct 14 ms 3408 KB Output is correct
6 Correct 14 ms 3352 KB Output is correct
7 Correct 12 ms 3348 KB Output is correct
8 Correct 15 ms 3388 KB Output is correct
9 Correct 12 ms 3192 KB Output is correct
10 Correct 13 ms 3284 KB Output is correct
11 Correct 13 ms 3156 KB Output is correct
12 Correct 16 ms 3076 KB Output is correct
13 Correct 13 ms 3412 KB Output is correct
14 Correct 13 ms 3352 KB Output is correct
15 Correct 12 ms 3348 KB Output is correct
16 Correct 12 ms 3348 KB Output is correct
17 Correct 11 ms 3352 KB Output is correct
18 Correct 418 ms 2308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2788 KB Output is correct
2 Correct 13 ms 3020 KB Output is correct
3 Correct 17 ms 3344 KB Output is correct
4 Correct 18 ms 3412 KB Output is correct
5 Correct 15 ms 3348 KB Output is correct
6 Correct 14 ms 3284 KB Output is correct
7 Correct 15 ms 3284 KB Output is correct
8 Correct 21 ms 3156 KB Output is correct
9 Correct 14 ms 3156 KB Output is correct
10 Correct 11 ms 3412 KB Output is correct
11 Correct 11 ms 3348 KB Output is correct
12 Correct 12 ms 3344 KB Output is correct
13 Correct 14 ms 3396 KB Output is correct
14 Correct 12 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3408 KB Output is correct
2 Correct 12 ms 3440 KB Output is correct
3 Correct 14 ms 3380 KB Output is correct
4 Correct 11 ms 3028 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 5 ms 1748 KB Output is correct
7 Correct 12 ms 2820 KB Output is correct
8 Correct 14 ms 3028 KB Output is correct
9 Correct 13 ms 2984 KB Output is correct
10 Correct 4 ms 1364 KB Output is correct
11 Correct 11 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 6 ms 1876 KB Output is correct
3 Correct 6 ms 1912 KB Output is correct
4 Correct 5 ms 1844 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 8 ms 1800 KB Output is correct
8 Correct 7 ms 1812 KB Output is correct
9 Correct 6 ms 1748 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 4 ms 1620 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 772 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 776 KB Output is correct
25 Correct 1 ms 776 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 776 KB Output is correct
32 Correct 169 ms 3408 KB Output is correct
33 Correct 330 ms 3416 KB Output is correct
34 Correct 446 ms 3404 KB Output is correct
35 Correct 13 ms 3444 KB Output is correct
36 Correct 14 ms 3408 KB Output is correct
37 Correct 14 ms 3352 KB Output is correct
38 Correct 12 ms 3348 KB Output is correct
39 Correct 15 ms 3388 KB Output is correct
40 Correct 12 ms 3192 KB Output is correct
41 Correct 13 ms 3284 KB Output is correct
42 Correct 13 ms 3156 KB Output is correct
43 Correct 16 ms 3076 KB Output is correct
44 Correct 13 ms 3412 KB Output is correct
45 Correct 13 ms 3352 KB Output is correct
46 Correct 12 ms 3348 KB Output is correct
47 Correct 12 ms 3348 KB Output is correct
48 Correct 11 ms 3352 KB Output is correct
49 Correct 418 ms 2308 KB Output is correct
50 Correct 11 ms 2788 KB Output is correct
51 Correct 13 ms 3020 KB Output is correct
52 Correct 17 ms 3344 KB Output is correct
53 Correct 18 ms 3412 KB Output is correct
54 Correct 15 ms 3348 KB Output is correct
55 Correct 14 ms 3284 KB Output is correct
56 Correct 15 ms 3284 KB Output is correct
57 Correct 21 ms 3156 KB Output is correct
58 Correct 14 ms 3156 KB Output is correct
59 Correct 11 ms 3412 KB Output is correct
60 Correct 11 ms 3348 KB Output is correct
61 Correct 12 ms 3344 KB Output is correct
62 Correct 14 ms 3396 KB Output is correct
63 Correct 12 ms 3156 KB Output is correct
64 Correct 14 ms 3408 KB Output is correct
65 Correct 12 ms 3440 KB Output is correct
66 Correct 14 ms 3380 KB Output is correct
67 Correct 11 ms 3028 KB Output is correct
68 Correct 2 ms 980 KB Output is correct
69 Correct 5 ms 1748 KB Output is correct
70 Correct 12 ms 2820 KB Output is correct
71 Correct 14 ms 3028 KB Output is correct
72 Correct 13 ms 2984 KB Output is correct
73 Correct 4 ms 1364 KB Output is correct
74 Correct 11 ms 2772 KB Output is correct
75 Correct 239 ms 3352 KB Output is correct
76 Correct 376 ms 3412 KB Output is correct
77 Correct 543 ms 3412 KB Output is correct
78 Correct 510 ms 3404 KB Output is correct
79 Correct 544 ms 3404 KB Output is correct
80 Correct 12 ms 3348 KB Output is correct
81 Correct 13 ms 3428 KB Output is correct
82 Correct 14 ms 3348 KB Output is correct
83 Correct 13 ms 3364 KB Output is correct
84 Correct 14 ms 3484 KB Output is correct
85 Correct 18 ms 3416 KB Output is correct
86 Correct 15 ms 3412 KB Output is correct
87 Correct 14 ms 3380 KB Output is correct
88 Correct 16 ms 3412 KB Output is correct
89 Correct 17 ms 3476 KB Output is correct
90 Correct 28 ms 3424 KB Output is correct
91 Correct 26 ms 3404 KB Output is correct
92 Correct 31 ms 3348 KB Output is correct
93 Correct 35 ms 3352 KB Output is correct
94 Correct 32 ms 3400 KB Output is correct
95 Correct 33 ms 3348 KB Output is correct
96 Correct 110 ms 3160 KB Output is correct
97 Correct 377 ms 3404 KB Output is correct
98 Correct 537 ms 3284 KB Output is correct
99 Correct 619 ms 3264 KB Output is correct
100 Correct 402 ms 2216 KB Output is correct