Submission #757661

# Submission time Handle Problem Language Result Execution time Memory
757661 2023-06-13T14:16:00 Z Rafi22 Toy Train (IOI17_train) C++14
100 / 100
329 ms 1656 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=5007;

int a[N],r[N];
vector<int>G[N];
vector<int>RG[N];
int ile[N];
bool is[N];

vector<int> who_wins(vector<int>a,vector<int>r,vector<int>U,vector<int>V)
{
    int n=sz(a),m=sz(U);
    vector<int>ans(n,1);
    for(int i=0;i<m;i++)
    {
        G[U[i]].pb(V[i]);
        RG[V[i]].pb(U[i]);
    }
    while(true)
    {
        memset(ile,0,sizeof ile);
        memset(is,0,sizeof is);
        deque<int>Q;
        for(int i=0;i<n;i++)
        {
            if(r[i])
            {
                Q.pb(i);
                is[i]=1;
            }
        }
        while(sz(Q)>0)
        {
            int v=Q[0];
            Q.pop_front();
            for(auto u:RG[v])
            {
                if(is[u]) continue;
                ile[u]++;
                if(a[u]==1||ile[u]==sz(G[u]))
                {
                    is[u]=1;
                    Q.pb(u);
                }
            }
        }
        bool xd=0;
        for(int i=0;i<n;i++) if(!is[i]) ans[i]=0;
        for(int i=0;i<n;i++)
        {
            if(!r[i]) continue;
            int c=0;
            for(auto u:G[i]) if(is[u]) c++;
            if(c==0||(a[i]==0&&c!=sz(G[i])))
            {
                r[i]=0;
                xd=1;
                break;
            }
        }
        if(!xd) break;
    }
    return ans;
}
/*
vector<int> who_wins1(vector<int>a,vector<int>r,vector<int>U,vector<int>V)
{
    int n=sz(a),m=sz(U);
    vector<int>DP(n,0);
    vector<int>p(n,0);
    vector<int>q(n,0);
    for(int i=0;i<m;i++)
    {
        if(U[i]==V[i]) p[U[i]]=1;
        else q[U[i]]=1;
    }
    for(int i=n-1;i>=0;i--)
    {
        if(q[i]) DP[i]=DP[i+1];
        else DP[i]=r[i];
        if(p[i])
        {
            if(a[i]==0&&r[i]==0) DP[i]=0;
            if(a[i]==1&&r[i]==1) DP[i]=1;
        }
    }
    return DP;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n),r(n);
    for(int i=0;i<n;i++)
    {
        a[i]=rand()%2;
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<n;i++)
    {
        r[i]=rand()%2;
        cout<<r[i]<<" ";
    }
    cout<<endl;
    vector<int>U,V;
    for(int i=0;i<n-1;i++)
    {
        int t=rand()%3;
        if(t==0||t==2)
        {
            U.pb(i);
            V.pb(i);
        }
        if(t==1||t==2)
        {
            U.pb(i);
            V.pb(i+1);
        }
    }
    U.pb(n-1);
    V.pb(n-1);
    for(auto a:U) cout<<a<<" ";
    cout<<endl;
    for(auto a:V) cout<<a<<" ";
    cout<<endl;
    vector<int>x=who_wins(a,r,U,V);
    vector<int>y=who_wins1(a,r,U,V);
    for(auto a:x) cout<<a<<" ";
    cout<<endl;
    for(auto a:y) cout<<a<<" ";
    cout<<endl;

    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 118 ms 1072 KB Output is correct
2 Correct 135 ms 1076 KB Output is correct
3 Correct 122 ms 1076 KB Output is correct
4 Correct 148 ms 1068 KB Output is correct
5 Correct 131 ms 980 KB Output is correct
6 Correct 118 ms 1128 KB Output is correct
7 Correct 164 ms 1064 KB Output is correct
8 Correct 30 ms 1084 KB Output is correct
9 Correct 120 ms 972 KB Output is correct
10 Correct 75 ms 1044 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 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 548 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 548 KB Output is correct
12 Correct 1 ms 468 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 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 552 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 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 1436 KB Output is correct
2 Correct 113 ms 1432 KB Output is correct
3 Correct 156 ms 1428 KB Output is correct
4 Correct 7 ms 1364 KB Output is correct
5 Correct 38 ms 1576 KB Output is correct
6 Correct 33 ms 1596 KB Output is correct
7 Correct 8 ms 1620 KB Output is correct
8 Correct 10 ms 1492 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 7 ms 1464 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 7 ms 1456 KB Output is correct
13 Correct 8 ms 1620 KB Output is correct
14 Correct 10 ms 1620 KB Output is correct
15 Correct 8 ms 1588 KB Output is correct
16 Correct 8 ms 1592 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct
18 Correct 234 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1212 KB Output is correct
2 Correct 11 ms 1416 KB Output is correct
3 Correct 18 ms 1492 KB Output is correct
4 Correct 275 ms 1492 KB Output is correct
5 Correct 17 ms 1492 KB Output is correct
6 Correct 21 ms 1572 KB Output is correct
7 Correct 44 ms 1460 KB Output is correct
8 Correct 77 ms 1536 KB Output is correct
9 Correct 207 ms 1504 KB Output is correct
10 Correct 8 ms 1620 KB Output is correct
11 Correct 8 ms 1620 KB Output is correct
12 Correct 8 ms 1584 KB Output is correct
13 Correct 8 ms 1492 KB Output is correct
14 Correct 7 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1492 KB Output is correct
2 Correct 8 ms 1364 KB Output is correct
3 Correct 8 ms 1364 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 5 ms 1140 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 1072 KB Output is correct
2 Correct 135 ms 1076 KB Output is correct
3 Correct 122 ms 1076 KB Output is correct
4 Correct 148 ms 1068 KB Output is correct
5 Correct 131 ms 980 KB Output is correct
6 Correct 118 ms 1128 KB Output is correct
7 Correct 164 ms 1064 KB Output is correct
8 Correct 30 ms 1084 KB Output is correct
9 Correct 120 ms 972 KB Output is correct
10 Correct 75 ms 1044 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 1 ms 468 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 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 548 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 548 KB Output is correct
23 Correct 1 ms 468 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 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 552 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 552 KB Output is correct
32 Correct 67 ms 1436 KB Output is correct
33 Correct 113 ms 1432 KB Output is correct
34 Correct 156 ms 1428 KB Output is correct
35 Correct 7 ms 1364 KB Output is correct
36 Correct 38 ms 1576 KB Output is correct
37 Correct 33 ms 1596 KB Output is correct
38 Correct 8 ms 1620 KB Output is correct
39 Correct 10 ms 1492 KB Output is correct
40 Correct 7 ms 1492 KB Output is correct
41 Correct 7 ms 1464 KB Output is correct
42 Correct 7 ms 1492 KB Output is correct
43 Correct 7 ms 1456 KB Output is correct
44 Correct 8 ms 1620 KB Output is correct
45 Correct 10 ms 1620 KB Output is correct
46 Correct 8 ms 1588 KB Output is correct
47 Correct 8 ms 1592 KB Output is correct
48 Correct 8 ms 1620 KB Output is correct
49 Correct 234 ms 1248 KB Output is correct
50 Correct 7 ms 1212 KB Output is correct
51 Correct 11 ms 1416 KB Output is correct
52 Correct 18 ms 1492 KB Output is correct
53 Correct 275 ms 1492 KB Output is correct
54 Correct 17 ms 1492 KB Output is correct
55 Correct 21 ms 1572 KB Output is correct
56 Correct 44 ms 1460 KB Output is correct
57 Correct 77 ms 1536 KB Output is correct
58 Correct 207 ms 1504 KB Output is correct
59 Correct 8 ms 1620 KB Output is correct
60 Correct 8 ms 1620 KB Output is correct
61 Correct 8 ms 1584 KB Output is correct
62 Correct 8 ms 1492 KB Output is correct
63 Correct 7 ms 1492 KB Output is correct
64 Correct 8 ms 1492 KB Output is correct
65 Correct 8 ms 1364 KB Output is correct
66 Correct 8 ms 1364 KB Output is correct
67 Correct 7 ms 1236 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 4 ms 980 KB Output is correct
70 Correct 5 ms 1140 KB Output is correct
71 Correct 5 ms 1108 KB Output is correct
72 Correct 5 ms 1236 KB Output is correct
73 Correct 2 ms 724 KB Output is correct
74 Correct 5 ms 1180 KB Output is correct
75 Correct 114 ms 1608 KB Output is correct
76 Correct 149 ms 1656 KB Output is correct
77 Correct 212 ms 1628 KB Output is correct
78 Correct 201 ms 1636 KB Output is correct
79 Correct 205 ms 1584 KB Output is correct
80 Correct 10 ms 1564 KB Output is correct
81 Correct 16 ms 1492 KB Output is correct
82 Correct 24 ms 1492 KB Output is correct
83 Correct 59 ms 1604 KB Output is correct
84 Correct 13 ms 1624 KB Output is correct
85 Correct 69 ms 1492 KB Output is correct
86 Correct 29 ms 1608 KB Output is correct
87 Correct 14 ms 1600 KB Output is correct
88 Correct 93 ms 1608 KB Output is correct
89 Correct 42 ms 1492 KB Output is correct
90 Correct 57 ms 1588 KB Output is correct
91 Correct 96 ms 1588 KB Output is correct
92 Correct 80 ms 1620 KB Output is correct
93 Correct 116 ms 1492 KB Output is correct
94 Correct 138 ms 1596 KB Output is correct
95 Correct 104 ms 1592 KB Output is correct
96 Correct 93 ms 1492 KB Output is correct
97 Correct 260 ms 1604 KB Output is correct
98 Correct 329 ms 1568 KB Output is correct
99 Correct 325 ms 1540 KB Output is correct
100 Correct 236 ms 1236 KB Output is correct