結果

問題 No.762 PDCAパス
ユーザー hiragnhiragn
提出日時 2022-11-29 07:55:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 558 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,804 KB
最終ジャッジ日時 2024-04-16 04:01:36
合計ジャッジ時間 11,840 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 29 ms
10,752 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 31 ms
10,880 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 31 ms
10,752 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 30 ms
10,752 KB
testcase_18 AC 29 ms
10,752 KB
testcase_19 AC 30 ms
10,752 KB
testcase_20 AC 30 ms
10,880 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 367 ms
11,776 KB
testcase_23 AC 365 ms
11,776 KB
testcase_24 AC 543 ms
34,804 KB
testcase_25 AC 542 ms
34,724 KB
testcase_26 AC 402 ms
13,696 KB
testcase_27 AC 399 ms
13,952 KB
testcase_28 AC 555 ms
32,848 KB
testcase_29 AC 558 ms
32,932 KB
testcase_30 AC 493 ms
25,024 KB
testcase_31 AC 512 ms
25,028 KB
testcase_32 AC 507 ms
25,044 KB
testcase_33 AC 469 ms
22,488 KB
testcase_34 AC 490 ms
22,348 KB
testcase_35 AC 484 ms
22,348 KB
testcase_36 AC 420 ms
14,892 KB
testcase_37 AC 414 ms
14,900 KB
testcase_38 AC 421 ms
14,772 KB
testcase_39 AC 426 ms
14,900 KB
testcase_40 AC 402 ms
14,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def main():
    mod = 10 ** 9 + 7
    n, m = map(int, input().split())
    s = input()

    adj = defaultdict(list)
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if s[a] + s[b] in ["PD", "DC", "CA"]:
            adj[a].append(b)
        if s[b] + s[a] in ["PD", "DC", "CA"]:
            adj[b].append(a)

    wd = "PDCA"
    # dp[i][v]:PDCAのi文字目まで来ていて,終点が頂点vの経路数
    dp = [[0 for _ in range(n)] for _ in range(4)]

    # 1文字目
    for i in range(n):
        if s[i] == wd[0]:
            dp[0][i] = 1

    # 2文字目以降
    for i in range(1, len(wd)):
        for u in range(n):
            for v in adj[u]:
                if s[v] == wd[i]:
                    dp[i][v] += dp[i - 1][u]
                    dp[i][v] %= mod

    res = sum(dp[3]) % mod
    print(res)


if __name__ == "__main__":
    main()
0