답안 #793566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793566 2023-07-26T02:58:04 Z skittles1412 장난감 기차 (IOI17_train) C++17
38 / 100
2000 ms 1656 KB
#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
    out << "[";
    for (int i = 0; i < sz(arr); i++) {
        if (i) {
            out << " ";
        }
        out << arr[i];
    }
    return out << "]";
}

vector<int> solve_must_vis(const vector<pair<int, int>>& edges,
                           const vector<int>& arr,
                           int team,
                           const vector<int>& nodes) {
    int n = sz(arr);

    vector<int> igraph[n];

    int o_deg[n] {};
    for (auto& [u, v] : edges) {
        igraph[v].push_back(u);
        o_deg[u]++;
    }

    int co_deg[n] {};
    bool queued[n] {};
    vector<int> q;

    auto push = [&](int u) -> void {
        if (queued[u]) {
            return;
        }
        queued[u] = true;
        q.push_back(u);
    };
    for (auto& a : nodes) {
        push(a);
    }

    while (sz(q)) {
        int u = q.back();
        q.pop_back();

        for (auto& v : igraph[u]) {
            co_deg[v]++;
            if (arr[v] == team) {
                push(v);
            } else {
                if (co_deg[v] == o_deg[v]) {
                    push(v);
                }
            }
        }
    }

    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if (queued[i]) {
            ans.push_back(i);
        }
    }
    return ans;
}

vector<int> who_wins(vector<int> arr,
                     vector<int> is_charging,
                     vector<int> edges_u,
                     vector<int> edges_v) {
    int n = sz(arr), m = sz(edges_u);

    vector<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
        edges.emplace_back(edges_u[i], edges_v[i]);
    }

    while (true) {
        vector<int> charging;
        for (int i = 0; i < n; i++) {
            if (is_charging[i]) {
                charging.push_back(i);
            }
        }
        auto must_charge = solve_must_vis(edges, arr, 1, charging);
        dbg(must_charge);

        bool is_must_charge[n] {};
        for (auto& a : must_charge) {
            is_must_charge[a] = true;
        }
        vector<int> wont_charge;
        for (int i = 0; i < n; i++) {
            if (!is_must_charge[i]) {
                wont_charge.push_back(i);
            }
        }

        auto all_wont_charge = solve_must_vis(edges, arr, 0, wont_charge);
        bool c_wont_charge[n] {};
        for (auto& a : all_wont_charge) {
            c_wont_charge[a] = true;
        }
        bool changed = false;
        for (auto& a : charging) {
            if (c_wont_charge[a]) {
                is_charging[a] = false;
                changed = true;
            }
        }

        if (changed) {
            continue;
        }
        vector<int> ans(n, 1);
        for (auto& a : all_wont_charge) {
            ans[a] = 0;
        }
        return ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 932 KB Output is correct
2 Correct 9 ms 980 KB Output is correct
3 Correct 7 ms 952 KB Output is correct
4 Correct 8 ms 980 KB Output is correct
5 Correct 6 ms 984 KB Output is correct
6 Correct 9 ms 956 KB Output is correct
7 Correct 4 ms 980 KB Output is correct
8 Correct 6 ms 952 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
10 Correct 5 ms 980 KB Output is correct
11 Correct 3 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 1536 KB Output is correct
2 Correct 860 ms 1652 KB Output is correct
3 Correct 1367 ms 1656 KB Output is correct
4 Correct 8 ms 1488 KB Output is correct
5 Correct 10 ms 1488 KB Output is correct
6 Correct 14 ms 1460 KB Output is correct
7 Correct 6 ms 1488 KB Output is correct
8 Correct 7 ms 1488 KB Output is correct
9 Correct 8 ms 1444 KB Output is correct
10 Correct 8 ms 1360 KB Output is correct
11 Correct 6 ms 1360 KB Output is correct
12 Correct 6 ms 1412 KB Output is correct
13 Correct 6 ms 1496 KB Output is correct
14 Correct 6 ms 1432 KB Output is correct
15 Correct 6 ms 1488 KB Output is correct
16 Correct 6 ms 1488 KB Output is correct
17 Correct 6 ms 1488 KB Output is correct
18 Execution timed out 2076 ms 1180 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1332 KB Output is correct
2 Correct 7 ms 1332 KB Output is correct
3 Correct 7 ms 1488 KB Output is correct
4 Correct 8 ms 1460 KB Output is correct
5 Correct 7 ms 1504 KB Output is correct
6 Correct 9 ms 1360 KB Output is correct
7 Correct 7 ms 1360 KB Output is correct
8 Correct 7 ms 1488 KB Output is correct
9 Correct 7 ms 1360 KB Output is correct
10 Correct 6 ms 1488 KB Output is correct
11 Correct 6 ms 1460 KB Output is correct
12 Correct 6 ms 1468 KB Output is correct
13 Correct 6 ms 1488 KB Output is correct
14 Correct 6 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1488 KB Output is correct
2 Correct 6 ms 1460 KB Output is correct
3 Correct 6 ms 1488 KB Output is correct
4 Correct 6 ms 1328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 5 ms 1084 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 1060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 932 KB Output is correct
2 Correct 9 ms 980 KB Output is correct
3 Correct 7 ms 952 KB Output is correct
4 Correct 8 ms 980 KB Output is correct
5 Correct 6 ms 984 KB Output is correct
6 Correct 9 ms 956 KB Output is correct
7 Correct 4 ms 980 KB Output is correct
8 Correct 6 ms 952 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
10 Correct 5 ms 980 KB Output is correct
11 Correct 3 ms 952 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 300 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 385 ms 1536 KB Output is correct
33 Correct 860 ms 1652 KB Output is correct
34 Correct 1367 ms 1656 KB Output is correct
35 Correct 8 ms 1488 KB Output is correct
36 Correct 10 ms 1488 KB Output is correct
37 Correct 14 ms 1460 KB Output is correct
38 Correct 6 ms 1488 KB Output is correct
39 Correct 7 ms 1488 KB Output is correct
40 Correct 8 ms 1444 KB Output is correct
41 Correct 8 ms 1360 KB Output is correct
42 Correct 6 ms 1360 KB Output is correct
43 Correct 6 ms 1412 KB Output is correct
44 Correct 6 ms 1496 KB Output is correct
45 Correct 6 ms 1432 KB Output is correct
46 Correct 6 ms 1488 KB Output is correct
47 Correct 6 ms 1488 KB Output is correct
48 Correct 6 ms 1488 KB Output is correct
49 Execution timed out 2076 ms 1180 KB Time limit exceeded
50 Halted 0 ms 0 KB -