結果

問題 No.2431 Viral Hotel
ユーザー nono00
提出日時 2023-08-19 01:55:12
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,773 bytes
コンパイル時間 3,237 ms
コンパイル使用メモリ 262,712 KB
実行使用メモリ 15,404 KB
最終ジャッジ日時 2024-11-28 14:29:35
合計ジャッジ時間 7,524 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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