Submission #584096

# Submission time Handle Problem Language Result Execution time Memory
584096 2022-06-26T19:23:26 Z yanndev Toy Train (IOI17_train) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 5042;
int dp[16][1 << 15];
vector<int> graph[MX];

// 5 pts 2h37

int solve(int pos, int vis, vector<int>& a, vector<int>& r) {
    if (dp[pos][vis] != -1)
        return dp[pos][vis];

    if (vis & (1 << pos) && r[pos])
        return (dp[pos][vis] = 1);

    if (a[pos]) {
        dp[pos][vis] = 0;
        for (auto& x: graph[pos]) {
            int nxtMsk = vis | (1 << x);
            if (solve(x, nxtMsk, a, r) == 1)
                dp[pos][vis] = 1;
        }
    } else {
        dp[pos][vis] = 1;
        for (auto& x: graph[pos]) {
            int nxtMsk = vis | (1 << x);
            if (solve(x, nxtMsk, a, r) == 0)
                dp[pos][vis] = 0;
        }
    }

    return dp[pos][vis];
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    int n;
    n = (int)a.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;
    }

    if (isChain) {
        for (int i = n - 1; i >= 0; i--) {
            bool hasSelf = false;
            bool hasNext = false;

            for (auto& x: graph[i]) {
                if (x == i) {
                    hasSelf = true;
                } else {
                    hasNext = true;
                }
            }

            if (a[i] == 1) {
                if (hasSelf && r[i])
                    ans[i] = 1;
                else if (hasNext)
                    ans[i] = ans[i + 1];
            } else {
                if (hasSelf && !r[i])
                    ans[i] = 0;
                else if (hasNext)
                    ans[i] = ans[i + 1];
                else
                    ans[i] = 1;
            }
        }
    } else if (n <= 15) {
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < n; i++)
            ans[i] = solve(i, 1 << i, a, r);
    }

    return ans;
}

signed main() {
    for (auto& x: who_wins({0, 1}, {1, 0}, {0, 0, 1, 1}, {0, 1, 0, 1}))
        cout << x << ' ';
}

Compilation message

/usr/bin/ld: /tmp/ccrKMR7o.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccg70Z2q.o:train.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status