Submission #607429

# Submission time Handle Problem Language Result Execution time Memory
607429 2022-07-26T17:15:48 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 mxScore[MX];
int deg[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> graph[MX];

void BFS(int layer) {
    queue<int> nxt {};
    for (int i = 0; i < n; i++) {
        deg[i] = 0;
        if (isCharge[i] && mxScore[i] == layer)
            nxt.push(layer);
    }

    for (int i = 0; i < n; i++)
        if (mxScore[i] == layer)
            for (auto& x: graph[i])
                deg[x]++;
    
    while (!nxt.empty()) {
        auto cur = nxt.front();
        auto chg = (isAlice[cur] ? max : min);
        nxt.pop();

        for (auto& x: graph[cur])
            if (--deg[x] == 0)
                mxScore[cur] = chg(mxScore[cur], mxScore[x]);

        mxScore[cur] += isCharge[cur];
    }
}

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

    for (int i = 0; i < (int)u.size(); i++)
        graph[v[i]].push_back(u[i]);
    for (int i = 0; i < n; i++) {
        isAlice[i] = a[i];
        isCharge[i] = r[i];
    }

    for (int layer = 0; layer <= (int)r.size(); layer++)
        BFS(layer);

    vector<int> ans (n);
    for (int i = 0; i < n; i++)
        ans[i] = mxScore[i] >= (int)r.size() + 1;
    return ans;
}

Compilation message

train.cpp: In function 'void BFS(int)':
train.cpp:14:25: error: 'n' was not declared in this scope
   14 |     for (int i = 0; i < n; i++) {
      |                         ^
train.cpp:20:25: error: 'n' was not declared in this scope
   20 |     for (int i = 0; i < n; i++)
      |                         ^
train.cpp:27:42: error: overloaded function with no contextual type information
   27 |         auto chg = (isAlice[cur] ? max : min);
      |                                          ^~~
train.cpp:27:42: error: overloaded function with no contextual type information
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:40:9: warning: unused variable 'myStations' [-Wunused-variable]
   40 |     int myStations = 0;
      |         ^~~~~~~~~~