Submission #607546

# Submission time Handle Problem Language Result Execution time Memory
607546 2022-07-26T19:55:57 Z yanndev Toy Train (IOI17_train) C++17
0 / 100
316 ms 1088 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 5042;

int n;
int deg[MX];
bool vis[MX];
bool vis2[MX];
bool isOk[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> rgraph[MX];

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

    //cout << layer << ' ' << (int)nxt.size() << '\n';
    
    while (!nxt.empty()) {
        auto cur = nxt.front();
        //cout << "cur is " << cur << '\n';
        nxt.pop();

        if (vis[cur])
            continue;
        
        vis[cur] = true;

        for (auto& x: rgraph[cur]) {
            if (isOk[x] && !vis2[x] && (--deg[x] == 0 || isAlice[x])) {
                vis2[cur] = true;
                nxt.push(x);
            }
        }
    }

    for (int i = 0; i < n; i++)
        if (isOk[i] && !vis2[i])
            isOk[i] = false;
}

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

    for (int i = 0; i < (int)u.size(); i++)
        rgraph[v[i]].push_back(u[i]);
    
    for (int i = 0; i < n; i++) {
        isAlice[i] = a[i];
        isCharge[i] = r[i];
        isOk[i] = true;
        for (auto& x: rgraph[i])
            deg[x]++;
    }

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

    vector<int> ans (n);
    for (int i = 0; i < n; i++)
        ans[i] = isOk[i];
    return ans;
}

/*int main() {
    for (auto& x: who_wins({0, 1}, {1, 0}, {0, 0, 1, 1}, {0, 1, 0, 1}))
        cout << x << ' ';
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 724 KB 3rd lines differ - on the 6th 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 Correct 268 ms 1072 KB Output is correct
2 Correct 182 ms 1088 KB Output is correct
3 Correct 144 ms 980 KB Output is correct
4 Incorrect 176 ms 1084 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 127 ms 944 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 115 ms 1048 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 316 ms 724 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -