Submission #1025427

# Submission time Handle Problem Language Result Execution time Memory
1025427 2024-07-17T03:08:44 Z shiomusubi496 Toy Train (IOI17_train) C++17
38 / 100
236 ms 262144 KB
#include "train.h"

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)

using namespace std;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

using ll = long long;

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
    int n = a.size(), m = u.size();
    if (count(all(r), 1) == 0) return r;
    if (count(all(r), 1) == n) return r;
    vector<vector<int>> g(n), rg(n);
    rep (i, m) {
        g[u[i]].push_back(v[i]);
        rg[v[i]].push_back(u[i]);
    }
    auto calc = [&](vector<int> r, bool f) -> vector<int> {
        queue<int> que;
        rep (i, n) {
            if (r[i]) que.push(i);
        }
        vector<int> deg(n);
        rep (i, n) deg[i] = g[i].size();
        while (!que.empty()) {
            int i = que.front(); que.pop();
            for (int j : rg[i]) {
                if (r[j]) continue;
                if (a[j] == f) {
                    r[j] = true;
                }
                else {
                    if ((--deg[j]) == 0) {
                        r[j] = true;
                    }
                }
                if (r[j]) que.push(j);
            }
        }
        return r;
    };
    auto r2 = calc(r, 1);
    if (count(all(r2), 1) == n) return r2;
    rep (i, n) r2[i] ^= 1;
    auto r3 = calc(r2, 0);
    vector<int> idx(n, -1);
    int cnt = 0;
    rep (i, n) {
        if (!r3[i]) {
            idx[i] = cnt++;
        }
    }
    vector<int> a2(cnt), r4(cnt);
    rep (i, n) {
        if (idx[i] == -1) continue;
        a2[idx[i]] = a[i];
        r4[idx[i]] = r[i];
    }
    vector<int> u2, v2;
    rep (i, m) {
        if (idx[u[i]] == -1 || idx[v[i]] == -1) continue;
        u2.push_back(idx[u[i]]);
        v2.push_back(idx[v[i]]);
    }
    auto res = who_wins(a2, r4, u2, v2);
    vector<int> ans(n);
    rep (i, n) {
        if (idx[i] == -1) ans[i] = 0;
        else ans[i] = res[idx[i]];
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2652 KB Output is correct
2 Correct 7 ms 4188 KB Output is correct
3 Correct 6 ms 3676 KB Output is correct
4 Correct 6 ms 3344 KB Output is correct
5 Correct 5 ms 2692 KB Output is correct
6 Correct 5 ms 2648 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 7 ms 4648 KB Output is correct
9 Correct 5 ms 2396 KB Output is correct
10 Correct 4 ms 1884 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 236 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2140 KB Output is correct
2 Correct 6 ms 1880 KB Output is correct
3 Correct 5 ms 1548 KB Output is correct
4 Correct 6 ms 1368 KB Output is correct
5 Correct 9 ms 1884 KB Output is correct
6 Correct 7 ms 2136 KB Output is correct
7 Correct 8 ms 2140 KB Output is correct
8 Correct 9 ms 1368 KB Output is correct
9 Correct 7 ms 1624 KB Output is correct
10 Correct 6 ms 1372 KB Output is correct
11 Correct 5 ms 1396 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 6 ms 1776 KB Output is correct
14 Correct 6 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1884 KB Output is correct
2 Correct 6 ms 1372 KB Output is correct
3 Correct 8 ms 2104 KB Output is correct
4 Correct 5 ms 1368 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 3 ms 1116 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 3 ms 1116 KB Output is correct
9 Correct 4 ms 1116 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 4 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2652 KB Output is correct
2 Correct 7 ms 4188 KB Output is correct
3 Correct 6 ms 3676 KB Output is correct
4 Correct 6 ms 3344 KB Output is correct
5 Correct 5 ms 2692 KB Output is correct
6 Correct 5 ms 2648 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 7 ms 4648 KB Output is correct
9 Correct 5 ms 2396 KB Output is correct
10 Correct 4 ms 1884 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Runtime error 236 ms 262144 KB Execution killed with signal 9
33 Halted 0 ms 0 KB -