Submission #797693

# Submission time Handle Problem Language Result Execution time Memory
797693 2023-07-29T19:01:45 Z PixelCat Toy Train (IOI17_train) C++14
0 / 100
6 ms 1876 KB
#ifdef NYAOWO
#include "grader.cpp"
#endif

#include "train.h"

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 5000;

vector<int> adj[MAXN + 10];
vector<int> rev[MAXN + 10];
int odeg[MAXN + 10];
int ok[MAXN + 10];

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

    For(i, 0, m - 1) {
        adj[u[i]].eb(v[i]);
        rev[v[i]].eb(u[i]);
        odeg[u[i]]++;
    }
    int rt = -1;
    For(i, 0, n - 1) if(r[i]) {
        rt = i;
    }

    memset(ok, 0, sizeof(ok));
    queue<int> que;
    que.emplace(rt);
    ok[rt] = 1;
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(auto &i:rev[cur]) if(ok[i] == 0) {
            ok[i] = 1;
            que.emplace(i);
        }
    }

    For(i, 0, n - 1) if(!ok[i]) que.emplace(i);
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(auto &i:rev[cur]) if(ok[i]) {
            odeg[i]--;
            if(a[i] == 0 || (a[i] == 1 && odeg[i] == 0)) {
                ok[i] = 0;
                que.emplace(i);
            }
        }
    }

    if(!ok[rt]) {
        For(i, 0, n - 1) ok[i] = 0;
    }

    vector<i32> res(n);
    For(i, 0, n - 1) res[i] = (i32) ok[i];
    return res;
}

/*

2 4
0 1
1 0
0 0
0 1
1 0
1 1

1 1

*/
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1196 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 1 ms 596 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1836 KB Output is correct
2 Correct 5 ms 1836 KB Output is correct
3 Correct 5 ms 1748 KB Output is correct
4 Correct 6 ms 1876 KB Output is correct
5 Correct 6 ms 1844 KB Output is correct
6 Incorrect 6 ms 1836 KB 3rd lines differ - on the 47th token, expected: '1', found: '0'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1580 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1876 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1196 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -