Submission #224434

# Submission time Handle Problem Language Result Execution time Memory
224434 2020-04-17T22:05:47 Z thebes Toy Train (IOI17_train) C++14
100 / 100
663 ms 1536 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm")
#include "train.h"
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

const int MN = 5005;
int N, M, i, j, x, ok[MN], deg[MN], arr[MN], ch[MN], vs[MN], prop[MN], rf[MN], dn;
vi adj[MN]; queue<int> q;

inline void bfs(){
    for(i=0;i<N;i++)
        deg[i]=vs[i]=prop[i]=0;
    for(i=0;i<N;i++){
        for(auto v : adj[i])
            deg[v]++;
    }
    for(i=0;i<N;i++){
        rf[i]=ok[i];
        if(ok[i]&&ch[i]){
            for(auto v : adj[i]){
                if(vs[v]) continue;
                if(arr[v]||!(--deg[v])){
                    vs[v]=1;
                    q.push(v);
                }
            }
            prop[i]=1;
        }
        ok[i]=0;
    }
    while(q.size()){
        x=q.front(); q.pop();
        ok[x]=1;
        if(prop[x]) continue;
        for(auto v : adj[x]){
            if(vs[v]) continue;
            if(arr[v]||!(--deg[v])){
                vs[v]=1;
                q.push(v);
            }
        }
    }
    int fl=0;
    for(i=0;i<N;i++){
        if(ok[i]!=rf[i]) fl=1;
    }
    if(!fl) dn=1;
}

vi who_wins(vi a,vi r,vi u,vi v){
    N = (int)a.size();
    M = (int)u.size();
    for(i=0;i<N;i++)
        arr[i]=a[i],ch[i]=r[i];
    for(i=0;i<M;i++)
        adj[v[i]].pb(u[i]);
    memset(ok,1,sizeof(ok));
    for(j=0;j<N&&!dn;j++)
        bfs();
    vi res;
    for(i=0;i<N;i++)
        res.pb(ok[i]);
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1024 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 1024 KB Output is correct
4 Correct 12 ms 1024 KB Output is correct
5 Correct 11 ms 1024 KB Output is correct
6 Correct 11 ms 1024 KB Output is correct
7 Correct 11 ms 1024 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 10 ms 1024 KB Output is correct
10 Correct 10 ms 1024 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 1528 KB Output is correct
2 Correct 206 ms 1452 KB Output is correct
3 Correct 278 ms 1528 KB Output is correct
4 Correct 13 ms 1536 KB Output is correct
5 Correct 17 ms 1408 KB Output is correct
6 Correct 16 ms 1408 KB Output is correct
7 Correct 13 ms 1408 KB Output is correct
8 Correct 13 ms 1536 KB Output is correct
9 Correct 12 ms 1408 KB Output is correct
10 Correct 12 ms 1408 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 13 ms 1408 KB Output is correct
14 Correct 13 ms 1408 KB Output is correct
15 Correct 13 ms 1536 KB Output is correct
16 Correct 13 ms 1408 KB Output is correct
17 Correct 13 ms 1408 KB Output is correct
18 Correct 323 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1280 KB Output is correct
2 Correct 13 ms 1280 KB Output is correct
3 Correct 13 ms 1408 KB Output is correct
4 Correct 14 ms 1536 KB Output is correct
5 Correct 13 ms 1408 KB Output is correct
6 Correct 14 ms 1408 KB Output is correct
7 Correct 13 ms 1408 KB Output is correct
8 Correct 13 ms 1408 KB Output is correct
9 Correct 13 ms 1408 KB Output is correct
10 Correct 13 ms 1536 KB Output is correct
11 Correct 13 ms 1408 KB Output is correct
12 Correct 14 ms 1408 KB Output is correct
13 Correct 14 ms 1536 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1408 KB Output is correct
2 Correct 14 ms 1408 KB Output is correct
3 Correct 13 ms 1408 KB Output is correct
4 Correct 14 ms 1408 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 8 ms 1024 KB Output is correct
7 Correct 10 ms 1152 KB Output is correct
8 Correct 10 ms 1152 KB Output is correct
9 Correct 10 ms 1152 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 10 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1024 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 1024 KB Output is correct
4 Correct 12 ms 1024 KB Output is correct
5 Correct 11 ms 1024 KB Output is correct
6 Correct 11 ms 1024 KB Output is correct
7 Correct 11 ms 1024 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 10 ms 1024 KB Output is correct
10 Correct 10 ms 1024 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 111 ms 1528 KB Output is correct
33 Correct 206 ms 1452 KB Output is correct
34 Correct 278 ms 1528 KB Output is correct
35 Correct 13 ms 1536 KB Output is correct
36 Correct 17 ms 1408 KB Output is correct
37 Correct 16 ms 1408 KB Output is correct
38 Correct 13 ms 1408 KB Output is correct
39 Correct 13 ms 1536 KB Output is correct
40 Correct 12 ms 1408 KB Output is correct
41 Correct 12 ms 1408 KB Output is correct
42 Correct 12 ms 1408 KB Output is correct
43 Correct 12 ms 1408 KB Output is correct
44 Correct 13 ms 1408 KB Output is correct
45 Correct 13 ms 1408 KB Output is correct
46 Correct 13 ms 1536 KB Output is correct
47 Correct 13 ms 1408 KB Output is correct
48 Correct 13 ms 1408 KB Output is correct
49 Correct 323 ms 1144 KB Output is correct
50 Correct 12 ms 1280 KB Output is correct
51 Correct 13 ms 1280 KB Output is correct
52 Correct 13 ms 1408 KB Output is correct
53 Correct 14 ms 1536 KB Output is correct
54 Correct 13 ms 1408 KB Output is correct
55 Correct 14 ms 1408 KB Output is correct
56 Correct 13 ms 1408 KB Output is correct
57 Correct 13 ms 1408 KB Output is correct
58 Correct 13 ms 1408 KB Output is correct
59 Correct 13 ms 1536 KB Output is correct
60 Correct 13 ms 1408 KB Output is correct
61 Correct 14 ms 1408 KB Output is correct
62 Correct 14 ms 1536 KB Output is correct
63 Correct 12 ms 1408 KB Output is correct
64 Correct 13 ms 1408 KB Output is correct
65 Correct 14 ms 1408 KB Output is correct
66 Correct 13 ms 1408 KB Output is correct
67 Correct 14 ms 1408 KB Output is correct
68 Correct 5 ms 512 KB Output is correct
69 Correct 8 ms 1024 KB Output is correct
70 Correct 10 ms 1152 KB Output is correct
71 Correct 10 ms 1152 KB Output is correct
72 Correct 10 ms 1152 KB Output is correct
73 Correct 6 ms 640 KB Output is correct
74 Correct 10 ms 1024 KB Output is correct
75 Correct 175 ms 1528 KB Output is correct
76 Correct 243 ms 1528 KB Output is correct
77 Correct 329 ms 1528 KB Output is correct
78 Correct 336 ms 1528 KB Output is correct
79 Correct 329 ms 1532 KB Output is correct
80 Correct 13 ms 1408 KB Output is correct
81 Correct 14 ms 1408 KB Output is correct
82 Correct 15 ms 1408 KB Output is correct
83 Correct 16 ms 1536 KB Output is correct
84 Correct 16 ms 1536 KB Output is correct
85 Correct 15 ms 1408 KB Output is correct
86 Correct 19 ms 1408 KB Output is correct
87 Correct 13 ms 1408 KB Output is correct
88 Correct 21 ms 1408 KB Output is correct
89 Correct 17 ms 1536 KB Output is correct
90 Correct 33 ms 1408 KB Output is correct
91 Correct 33 ms 1528 KB Output is correct
92 Correct 51 ms 1408 KB Output is correct
93 Correct 42 ms 1408 KB Output is correct
94 Correct 44 ms 1408 KB Output is correct
95 Correct 47 ms 1528 KB Output is correct
96 Correct 112 ms 1400 KB Output is correct
97 Correct 390 ms 1528 KB Output is correct
98 Correct 609 ms 1528 KB Output is correct
99 Correct 663 ms 1396 KB Output is correct
100 Correct 323 ms 1144 KB Output is correct