Submission #641669

# Submission time Handle Problem Language Result Execution time Memory
641669 2022-09-17T12:07:17 Z piOOE Toy Train (IOI17_train) C++17
0 / 100
663 ms 1376 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;
using ll = long long;

constexpr int N = 5000;

vector<int> g[N];
bool dp[N];
int used[N], T = 0;
vector<int> stk, last;
int in_stk[N];

vector<int> r, a;

void dfs(int v) {
    used[v] = T;
    in_stk[v] = stk.size();
    stk.push_back(v);
    if (r[v]) {
        last.push_back(last.size() - 1);
    } else {
        last.push_back(last.back());
    }
    for (int to: g[v]) {
        if (in_stk[to] != -1) {
            if (a[v] ^ (last.back() < in_stk[to])) {
                dp[v] = true;
            }
        } else {
            if (used[to] != T) {
                dfs(to);
            }
            if (a[v] ^ a[to] ^ dp[to]) {
                dp[v] = true;
            }
        }
    }
    stk.pop_back();
    last.pop_back();
    in_stk[v] = -1;
};

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> A, std::vector<int> B) {
    ::a = a, ::r = r;
    int n = a.size(), m = A.size();
    for (int i = 0; i < m; ++i) {
        g[A[i]].push_back(B[i]);
    }
    last = {-1};
    vector<int> ans(n);
    for (int root = 0; root < n; ++root) {
        ++T;
        memset(dp, 0, sizeof(dp));
        dfs(root);
        ans[root] = dp[root] ^ a[root] ^ 1;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 1144 KB 3rd lines differ - on the 21st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 663 ms 1376 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 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -