Submission #583926

# Submission time Handle Problem Language Result Execution time Memory
583926 2022-06-26T13:45:48 Z PiejanVDC Toy Train (IOI17_train) C++17
0 / 100
163 ms 262144 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;

vector<int>tim;
vector<int>s,a,r;
vector<int>adj[15];
vector<int>ans(15,2);

int t = 1;

bool dfs(int u) {
    if(ans[u] != 2)
        return ans[u];
    if(tim[u] && !s.empty()) {
        if(s.back() >= tim[u])
            return 1;
        return 0;
    }

    tim[u] = t++;
    if(r[u])
        s.push_back(t-1);

    bool ok;
    if(a[u]) {
        ok = 0;
        for(auto z : adj[u]) {
            ok |= dfs(z);
            if(ok)
                break;
        }
    } else {
        ok = 1;
        for(auto z : adj[u]) {
            ok &= dfs(z);
            if(!ok)
                break;
        }
    }

    if(r[u])
        s.pop_back();
    tim[u] = 0;

    return ok;
}

vector<int>who_wins(vector<int>A, vector<int>R, vector<int>u, vector<int>v) {

    r = R;
    a = A;

    int n = r.size();
    int m = u.size();

    for(int i = 0 ; i < m ; i++) {
        adj[u[i]].push_back(v[i]);
    }

    vector<int>x;
    for(int i = 0 ; i < n ; i++)
        x.push_back(i);

    random_shuffle(x.begin(),x.end());

    for(int y = 0 ; y < n ; y++) {
        int i = x[y];
        t = 1;
        tim.clear();
        tim.resize(n,0);
        ans[i] = dfs(i);
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 848 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 163 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 1364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 848 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -