Submission #641665

# Submission time Handle Problem Language Result Execution time Memory
641665 2022-09-17T12:02:21 Z piOOE Toy Train (IOI17_train) C++17
5 / 100
2000 ms 1704 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;
using ll = long long;

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> A, std::vector<int> B) {
    int n = a.size(), m = A.size();
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        g[A[i]].push_back(B[i]);
    }
    vector<int> ans(n);
    for (int root = 0; root < n; ++root) {
        vector<bool> dp(n), used(n);
        vector<int> stk, last = {-1};
        vector<int> in_stk(n, -1);
        function<void(int)> dfs = [&](int v) {
            used[v] = true;
            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]) {
                        dfs(to);
                    }
                    if (a[v] ^ a[to] ^ dp[to]) {
                        dp[v] = true;
                    }
                }
            }
            stk.pop_back();
            last.pop_back();
            in_stk[v] = -1;
        };
        dfs(root);
        ans[root] = dp[root] ^ a[root] ^ 1;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 561 ms 1316 KB Output is correct
2 Correct 195 ms 1148 KB Output is correct
3 Correct 93 ms 980 KB Output is correct
4 Correct 35 ms 852 KB Output is correct
5 Correct 20 ms 852 KB Output is correct
6 Correct 11 ms 884 KB Output is correct
7 Correct 10 ms 888 KB Output is correct
8 Correct 10 ms 856 KB Output is correct
9 Correct 8 ms 864 KB Output is correct
10 Correct 7 ms 848 KB Output is correct
11 Correct 6 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 429 ms 1576 KB Output is correct
2 Correct 413 ms 1704 KB Output is correct
3 Correct 407 ms 1636 KB Output is correct
4 Execution timed out 2094 ms 1492 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1407 ms 1176 KB Output is correct
2 Correct 248 ms 1148 KB Output is correct
3 Correct 605 ms 1356 KB Output is correct
4 Correct 885 ms 1356 KB Output is correct
5 Correct 621 ms 1288 KB Output is correct
6 Incorrect 525 ms 1292 KB 3rd lines differ - on the 1524th token, expected: '0', found: '1'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 1304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 561 ms 1316 KB Output is correct
2 Correct 195 ms 1148 KB Output is correct
3 Correct 93 ms 980 KB Output is correct
4 Correct 35 ms 852 KB Output is correct
5 Correct 20 ms 852 KB Output is correct
6 Correct 11 ms 884 KB Output is correct
7 Correct 10 ms 888 KB Output is correct
8 Correct 10 ms 856 KB Output is correct
9 Correct 8 ms 864 KB Output is correct
10 Correct 7 ms 848 KB Output is correct
11 Correct 6 ms 824 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 268 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
16 Halted 0 ms 0 KB -