답안 #132470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132470 2019-07-19T01:02:53 Z tri 장난감 기차 (IOI17_train) C++14
100 / 100
577 ms 1912 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = true;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"), cout << flush; }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;

int V;
vi own, isC, numO;
vector<vi> aL;
vector<vi> rL;
vector<bool> rm;

vi fReach(vi &goal, int pro) {
    vi reach(V, 0);
    queue<int> q;

    for (int i : goal) {
        reach[i] = -1;
        q.push(i);
    }

    while (q.size()) {
        int cV = q.front();
        q.pop();
        for (int pV : rL[cV]) {
            if (rm[pV] || reach[pV] == -1) {
                continue;
            }
            if (own[pV] == pro) {
                reach[pV] = -1;
                q.push(pV);
            } else {
                reach[pV]++;
                if (reach[pV] == numO[pV]) {
                    reach[pV] = -1;
                    q.push(pV);
                }
            }
        }
    }
    for (int i = 0; i < V; i++) {
        if (reach[i] == -1) {
            reach[i] = 1;
        } else {
            reach[i] = 0;
        }
    }
    return reach;
}

vi who_wins(vi a, vi r, vi u, vi v) {
    V = a.size();
    own = a;
    isC = r;

    aL.resize(V);
    rL.resize(V);
    for (int i = 0; i < u.size(); i++) {
        aL[u[i]].pb(v[i]);
        rL[v[i]].pb(u[i]);
    }

    rm.resize(V);
    fill(rm.begin(), rm.end(), false);
    int rem = V;

    vi ans(V);

    numO.resize(V);
    for (int i = 0; i < V; i++) {
        numO[i] = aL[i].size();
    }

    while (rem > 0) {
        vi charge;
        for (int i = 0; i < V; i++) {
            if (!rm[i] && isC[i]) {
                charge.pb(i);
            }
        }

        vi reachCharge = fReach(charge, 1);
        vi cannotReach;
        for (int i = 0; i < V; i++) {
            if (!rm[i] && !reachCharge[i]) {
                cannotReach.pb(i);
            }
        }

        if (cannotReach.empty()) {
            for (int i = 0; i < V; i++) {
                if (!rm[i] && reachCharge[i]) {
                    ans[i] = 1;
                }
            }
            return ans;
        }

        vi trappable = fReach(cannotReach, 0);

        for (int i = 0; i < V; i++) {
            if (!rm[i] && trappable[i]) {
                ans[i] = 0;
                rm[i] = true;
                rem--;

                for (int pV : rL[i]) {
                    if(!rm[pV]){
                        numO[pV]--;
                    }
                }
            }
        }
    }

    return ans;
}

Compilation message

train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:128:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < u.size(); i++) {
                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1272 KB Output is correct
2 Correct 9 ms 1272 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 8 ms 1272 KB Output is correct
5 Correct 8 ms 1276 KB Output is correct
6 Correct 8 ms 1276 KB Output is correct
7 Correct 7 ms 1272 KB Output is correct
8 Correct 8 ms 1272 KB Output is correct
9 Correct 8 ms 1276 KB Output is correct
10 Correct 7 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 1800 KB Output is correct
2 Correct 232 ms 1784 KB Output is correct
3 Correct 315 ms 1656 KB Output is correct
4 Correct 12 ms 1656 KB Output is correct
5 Correct 13 ms 1656 KB Output is correct
6 Correct 13 ms 1784 KB Output is correct
7 Correct 12 ms 1656 KB Output is correct
8 Correct 12 ms 1656 KB Output is correct
9 Correct 11 ms 1660 KB Output is correct
10 Correct 12 ms 1656 KB Output is correct
11 Correct 11 ms 1656 KB Output is correct
12 Correct 11 ms 1656 KB Output is correct
13 Correct 12 ms 1656 KB Output is correct
14 Correct 12 ms 1656 KB Output is correct
15 Correct 12 ms 1656 KB Output is correct
16 Correct 12 ms 1656 KB Output is correct
17 Correct 12 ms 1656 KB Output is correct
18 Correct 472 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1528 KB Output is correct
2 Correct 12 ms 1520 KB Output is correct
3 Correct 12 ms 1716 KB Output is correct
4 Correct 13 ms 1656 KB Output is correct
5 Correct 13 ms 1784 KB Output is correct
6 Correct 12 ms 1656 KB Output is correct
7 Correct 12 ms 1656 KB Output is correct
8 Correct 12 ms 1656 KB Output is correct
9 Correct 11 ms 1656 KB Output is correct
10 Correct 13 ms 1656 KB Output is correct
11 Correct 12 ms 1656 KB Output is correct
12 Correct 13 ms 1784 KB Output is correct
13 Correct 13 ms 1784 KB Output is correct
14 Correct 12 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1776 KB Output is correct
2 Correct 12 ms 1692 KB Output is correct
3 Correct 15 ms 1784 KB Output is correct
4 Correct 15 ms 1656 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 7 ms 1272 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 8 ms 1016 KB Output is correct
9 Correct 8 ms 1144 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 8 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1272 KB Output is correct
2 Correct 9 ms 1272 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 8 ms 1272 KB Output is correct
5 Correct 8 ms 1276 KB Output is correct
6 Correct 8 ms 1276 KB Output is correct
7 Correct 7 ms 1272 KB Output is correct
8 Correct 8 ms 1272 KB Output is correct
9 Correct 8 ms 1276 KB Output is correct
10 Correct 7 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 118 ms 1800 KB Output is correct
33 Correct 232 ms 1784 KB Output is correct
34 Correct 315 ms 1656 KB Output is correct
35 Correct 12 ms 1656 KB Output is correct
36 Correct 13 ms 1656 KB Output is correct
37 Correct 13 ms 1784 KB Output is correct
38 Correct 12 ms 1656 KB Output is correct
39 Correct 12 ms 1656 KB Output is correct
40 Correct 11 ms 1660 KB Output is correct
41 Correct 12 ms 1656 KB Output is correct
42 Correct 11 ms 1656 KB Output is correct
43 Correct 11 ms 1656 KB Output is correct
44 Correct 12 ms 1656 KB Output is correct
45 Correct 12 ms 1656 KB Output is correct
46 Correct 12 ms 1656 KB Output is correct
47 Correct 12 ms 1656 KB Output is correct
48 Correct 12 ms 1656 KB Output is correct
49 Correct 472 ms 1400 KB Output is correct
50 Correct 10 ms 1528 KB Output is correct
51 Correct 12 ms 1520 KB Output is correct
52 Correct 12 ms 1716 KB Output is correct
53 Correct 13 ms 1656 KB Output is correct
54 Correct 13 ms 1784 KB Output is correct
55 Correct 12 ms 1656 KB Output is correct
56 Correct 12 ms 1656 KB Output is correct
57 Correct 12 ms 1656 KB Output is correct
58 Correct 11 ms 1656 KB Output is correct
59 Correct 13 ms 1656 KB Output is correct
60 Correct 12 ms 1656 KB Output is correct
61 Correct 13 ms 1784 KB Output is correct
62 Correct 13 ms 1784 KB Output is correct
63 Correct 12 ms 1656 KB Output is correct
64 Correct 13 ms 1776 KB Output is correct
65 Correct 12 ms 1692 KB Output is correct
66 Correct 15 ms 1784 KB Output is correct
67 Correct 15 ms 1656 KB Output is correct
68 Correct 3 ms 376 KB Output is correct
69 Correct 7 ms 1272 KB Output is correct
70 Correct 8 ms 1016 KB Output is correct
71 Correct 8 ms 1016 KB Output is correct
72 Correct 8 ms 1144 KB Output is correct
73 Correct 3 ms 504 KB Output is correct
74 Correct 8 ms 1020 KB Output is correct
75 Correct 188 ms 1744 KB Output is correct
76 Correct 278 ms 1780 KB Output is correct
77 Correct 361 ms 1784 KB Output is correct
78 Correct 371 ms 1912 KB Output is correct
79 Correct 365 ms 1816 KB Output is correct
80 Correct 13 ms 1656 KB Output is correct
81 Correct 13 ms 1784 KB Output is correct
82 Correct 14 ms 1656 KB Output is correct
83 Correct 13 ms 1656 KB Output is correct
84 Correct 14 ms 1656 KB Output is correct
85 Correct 15 ms 1656 KB Output is correct
86 Correct 14 ms 1784 KB Output is correct
87 Correct 13 ms 1668 KB Output is correct
88 Correct 16 ms 1656 KB Output is correct
89 Correct 14 ms 1788 KB Output is correct
90 Correct 21 ms 1656 KB Output is correct
91 Correct 19 ms 1656 KB Output is correct
92 Correct 31 ms 1744 KB Output is correct
93 Correct 32 ms 1656 KB Output is correct
94 Correct 34 ms 1656 KB Output is correct
95 Correct 34 ms 1656 KB Output is correct
96 Correct 102 ms 1680 KB Output is correct
97 Correct 363 ms 1784 KB Output is correct
98 Correct 577 ms 1776 KB Output is correct
99 Correct 574 ms 1784 KB Output is correct
100 Correct 453 ms 1528 KB Output is correct