結果

問題 No.2431 Viral Hotel
ユーザー nono00nono00
提出日時 2023-08-19 01:55:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,773 bytes
コンパイル時間 3,302 ms
コンパイル使用メモリ 261,300 KB
実行使用メモリ 13,572 KB
最終ジャッジ日時 2024-05-06 09:04:58
合計ジャッジ時間 7,311 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
10,408 KB
testcase_01 AC 73 ms
9,912 KB
testcase_02 AC 79 ms
10,616 KB
testcase_03 AC 113 ms
11,080 KB
testcase_04 AC 95 ms
12,228 KB
testcase_05 AC 102 ms
11,972 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 17 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 114 ms
13,572 KB
testcase_13 AC 88 ms
10,756 KB
testcase_14 AC 43 ms
7,548 KB
testcase_15 AC 16 ms
5,376 KB
testcase_16 AC 56 ms
10,776 KB
testcase_17 AC 34 ms
6,520 KB
testcase_18 AC 83 ms
12,216 KB
testcase_19 AC 53 ms
9,392 KB
testcase_20 AC 24 ms
6,400 KB
testcase_21 AC 19 ms
5,564 KB
testcase_22 AC 56 ms
8,520 KB
testcase_23 AC 64 ms
8,372 KB
testcase_24 AC 34 ms
7,296 KB
testcase_25 AC 79 ms
9,840 KB
testcase_26 AC 44 ms
8,680 KB
testcase_27 AC 55 ms
8,172 KB
testcase_28 AC 42 ms
7,156 KB
testcase_29 AC 42 ms
7,064 KB
testcase_30 AC 49 ms
7,280 KB
testcase_31 AC 68 ms
10,184 KB
testcase_32 AC 19 ms
5,376 KB
testcase_33 AC 42 ms
6,732 KB
testcase_34 AC 5 ms
5,376 KB
testcase_35 AC 14 ms
5,376 KB
testcase_36 AC 77 ms
10,340 KB
testcase_37 AC 48 ms
8,412 KB
testcase_38 AC 21 ms
6,528 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 102 ms
13,372 KB
testcase_44 AC 62 ms
9,192 KB
testcase_45 AC 48 ms
7,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

enum class EventType {
    RECOVER = 0,
    INFECT = 1,
    INFECTED = 2,
};

enum class State {
    FINE,
    RECOVER,
    INFECTED,
    GOODBYE,
};

struct Event {
    long long time;
    EventType type;
    int index;
    Event(long long time, EventType type, int index): time(time), type(type), index(index) {}
    friend auto operator<=>(const Event& lhs, const Event& rhs) = default;
};

void solve() {
    int N, K, M, P;
    std::cin >> N >> K >> M >> P;
    std::vector graph(N, std::vector<int>());
    for (int i = 0; i < M; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    std::vector<long long> S(N);
    for (int i = 0; i < N; i++) std::cin >> S[i];

    std::priority_queue<Event, std::vector<Event>, std::greater<Event>> events;
    for (int i = 0; i < K; i++) {
        int x;
        std::cin >> x;
        x--;
        events.emplace(0, EventType::INFECTED, x);
    }

    std::vector<State> states(N, State::FINE);
    while (not events.empty()) {
        auto [now, type, i] = events.top();
        events.pop();
        if (states[i] == State::GOODBYE) continue;
        if (type == EventType::RECOVER) {
            if (states[i] == State::GOODBYE) continue;
            states[i] = State::RECOVER;
        } else if (type == EventType::INFECT) {
            for (int to: graph[i]) {
                if (states[to] == State::FINE or states[to] == State::INFECTED) {
                    events.emplace(now, EventType::INFECTED, to);
                }
            }
        } else if (type == EventType::INFECTED) {
            if (states[i] == State::FINE) {
                states[i] = State::INFECTED;
                events.emplace(now + S[i], EventType::INFECT, i);
                events.emplace(now + P, EventType::RECOVER, i);
            } else if (states[i] == State::INFECTED) {
                states[i] = State::GOODBYE;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (states[i] == State::GOODBYE) ans++;
        // if (states[i] == State::GOODBYE) {
        //     std::cout << "GOODBYE" << ' ';
        // } else if (states[i] == State::FINE) {
        //     std::cout << "FINE" << ' ';
        // } else if (states[i] == State::INFECTED) {
        //     std::cout << "INFECTED" << ' ';
        // } else {
        //     std::cout << "RECOVER" << ' ';
        // }
    }
    // std::cout << std::endl;
    std::cout << ans << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    //  std::cin >> t;
    while (t--) nono::solve();
}
0