Submission #612628

# Submission time Handle Problem Language Result Execution time Memory
612628 2022-07-29T18:31:45 Z MohamedAliSaidane Toy Train (IOI17_train) C++14
0 / 100
2000 ms 1748 KB
#include <bits/stdc++.h>
//#include "train.h"
    using namespace std;

    typedef long long ll;
    typedef double ld;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    typedef vector<int> vi;
    typedef vector<ll> vll;
    typedef vector<pii> vpi;
    typedef vector<pll> vpl;

    #define pb push_back
    #define popb pop_back
    #define all(x) (x).begin(),(x).end()

    #define ff first
    #define ss second

    const int nax = 5004;
    const int MOD = 1e9 + 7;

    int n, m ;
    vi adj[nax], rev_adj[nax];
    int siz[nax];
    set<int> cur;
    int cnt[nax];
    void rec(int x)
    {
        if(cur.count(x) != 0)
            return ;
        cur.insert(x);
        for(auto e: rev_adj[x])
        {
            cnt[e]++;
            if(cnt[e] == siz[e])
                rec(e);
        }
    }
    vi who_wins(vi a, vi r, vi u, vi v)
    {
        n = a.size();
        m = u.size();

        for(int i=  0; i < m; i ++)
        {
            adj[u[i]].pb(v[i]);
            rev_adj[v[i]].pb(u[i]);
        }
        for(int i = 0 ; i < n; i ++ )
            siz[i] = (int)(adj[i].size());

        vi ans(n, 0);
        vi chrg;
        for(int i=  0 ; i < n;i ++)
            if(r[i])
                chrg.pb(i);
        int sz = chrg.size();
        if(sz == 0)
            return ans;
        for(int mask = 1; mask < (1 << sz); mask ++)
        {
            int cnt[n];
            memset(cnt, 0,sizeof(cnt));
            vi org;
            for(int i= 0; i < sz; i ++)
                if((1 << i)  & mask)
                    org.pb(chrg[i]);
            cur.clear();
            for(int i=  0 ; i < n;i ++)
                cnt[i] = 0 ;
            for(auto e: org)
            {
                rec(e);
            }
            bool flag= true;
            for(auto e: org)
            {
                if(a[e])
                {
                    if(cnt[e] == 0)
                        flag = false;
                }
                if(!a[e] && (cnt[e] != siz[e]))
                    flag = false;
            }
            if(flag)
            {
                for(auto e: cur)
                    ans[e] = 1;
            }
        }

        return ans;

    }
# Verdict Execution time Memory Grader output
1 Incorrect 247 ms 1148 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 1748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 1596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1364 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 247 ms 1148 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -