結果

問題 No.762 PDCAパス
ユーザー MisterMister
提出日時 2020-04-18 01:09:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 83,128 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-14 18:37:28
合計ジャッジ時間 4,100 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 20 ms
6,944 KB
testcase_23 AC 20 ms
6,944 KB
testcase_24 AC 42 ms
9,584 KB
testcase_25 AC 45 ms
9,600 KB
testcase_26 AC 21 ms
6,940 KB
testcase_27 AC 21 ms
6,940 KB
testcase_28 AC 61 ms
10,368 KB
testcase_29 AC 61 ms
10,496 KB
testcase_30 AC 55 ms
9,856 KB
testcase_31 AC 57 ms
9,728 KB
testcase_32 AC 55 ms
9,728 KB
testcase_33 AC 47 ms
8,960 KB
testcase_34 AC 48 ms
8,960 KB
testcase_35 AC 50 ms
8,832 KB
testcase_36 AC 36 ms
7,680 KB
testcase_37 AC 36 ms
7,808 KB
testcase_38 AC 35 ms
7,680 KB
testcase_39 AC 36 ms
7,680 KB
testcase_40 AC 36 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

constexpr int MOD = 1000000007;

void solve() {
    int n, m;
    std::string s;
    std::cin >> n >> m >> s;

    Graph<> graph(n);
    while (m--) {
        int u, v;
        std::cin >> u >> v;

        --u, --v;
        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
    }

    std::vector<int> dp(n, 0);
    for (int v = 0; v < n; ++v) {
        if (s[v] == 'P') dp[v] = 1;
    }

    auto ndp = dp;
    for (char c : std::string("DCA")) {
        std::fill(ndp.begin(), ndp.end(), 0);

        for (int v = 0; v < n; ++v) {
            if (s[v] != c) continue;

            for (auto e : graph[v]) {
                (ndp[v] += dp[e.dst]) %= MOD;
            }
        }

        std::swap(dp, ndp);
    }

    int ans = 0;
    for (auto x : dp) (ans += x) %= MOD;

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0