Submission #584081

# Submission time Handle Problem Language Result Execution time Memory
584081 2022-06-26T18:58:44 Z yanndev Toy Train (IOI17_train) C++17
0 / 100
7 ms 1000 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 5042;
vector<int> graph[MX];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    int n, m;
    n = (int)a.size();
    m = (int)u.size();

    for (int i = 0; i < MX; i++)
        graph[i].clear();

    vector<int> ans (n);
    bool isChain = true;

    for (int i = 0; i < (int)u.size(); i++) {
        graph[u[i]].push_back(v[i]);
        if (!(u[i] == v[i] || v[i] == u[i] + 1))
            isChain = false;
    }

    isChain = true;

    if (isChain) {
        for (int i = n - 1; i >= 0; i--) {
            bool hasSelf = false;
            bool isOk = false;
            for (auto& x: graph[i]) {
                if (x == i) {
                    hasSelf = true;
                } else {
                    isOk |= (bool)ans[x];
                }
            }

            if (hasSelf) {
                if (a[i] == 1) {
                    if (r[i] == 1)
                        isOk = true;
                } else {
                    if (r[i] == 0)
                        isOk = false;
                }
            }

            ans[i] = (int)isOk;
        }

        return ans;
    }

    return ans;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:8:12: warning: variable 'm' set but not used [-Wunused-but-set-variable]
    8 |     int n, m;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Incorrect 3 ms 724 KB 3rd lines differ - on the 4997th token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 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 Correct 5 ms 980 KB Output is correct
2 Correct 6 ms 1000 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Incorrect 5 ms 980 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 844 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 7 ms 980 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 Correct 3 ms 724 KB Output is correct
2 Incorrect 3 ms 724 KB 3rd lines differ - on the 4997th token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -