結果

問題 No.762 PDCAパス
ユーザー ntudantuda
提出日時 2022-10-30 22:25:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 612 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 95,664 KB
最終ジャッジ日時 2023-09-21 20:19:48
合計ジャッジ時間 11,462 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
72,392 KB
testcase_01 AC 111 ms
72,300 KB
testcase_02 AC 109 ms
72,160 KB
testcase_03 AC 110 ms
72,288 KB
testcase_04 AC 108 ms
72,280 KB
testcase_05 AC 109 ms
72,216 KB
testcase_06 AC 112 ms
72,280 KB
testcase_07 AC 109 ms
72,332 KB
testcase_08 AC 111 ms
72,292 KB
testcase_09 AC 111 ms
72,280 KB
testcase_10 AC 108 ms
72,192 KB
testcase_11 AC 110 ms
72,220 KB
testcase_12 AC 113 ms
72,280 KB
testcase_13 AC 109 ms
72,212 KB
testcase_14 AC 109 ms
72,348 KB
testcase_15 AC 107 ms
72,268 KB
testcase_16 AC 110 ms
72,264 KB
testcase_17 AC 110 ms
72,308 KB
testcase_18 AC 109 ms
72,308 KB
testcase_19 AC 110 ms
72,296 KB
testcase_20 AC 108 ms
72,284 KB
testcase_21 AC 109 ms
72,140 KB
testcase_22 AC 1,207 ms
89,220 KB
testcase_23 AC 1,220 ms
89,260 KB
testcase_24 AC 280 ms
95,664 KB
testcase_25 AC 270 ms
95,620 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
S = input()
UV = [list(map(int, input().split())) for _ in range(M)]
E = [[] for _ in range(N)]
A = ["P", "D", "C", "A"]

for u, v in UV:
    u -= 1
    v -= 1
    a = A.index(S[u])
    if a < 3 and S[v] == A[a + 1]:
        E[u].append(v)
    if 0 < a and S[v] == A[a - 1]:
        E[v].append(u)

#@lru_cache()
def dfs(x):
    if S[x] == "A":
        return 1
    ret = 0
    for v in E[x]:
        ret += dfs(v)
    return ret

ans = 0
for i in range(N):
    if S[i] == "P":
        ans += dfs(i)
        ans %= MOD
print(ans)
0