結果

問題 No.762 PDCAパス
ユーザー ntudantuda
提出日時 2022-10-30 22:31:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 449 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 99,536 KB
最終ジャッジ日時 2023-09-21 20:22:59
合計ジャッジ時間 11,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
72,224 KB
testcase_01 AC 103 ms
72,380 KB
testcase_02 AC 103 ms
72,460 KB
testcase_03 AC 104 ms
72,068 KB
testcase_04 AC 104 ms
72,492 KB
testcase_05 AC 104 ms
72,404 KB
testcase_06 AC 104 ms
72,336 KB
testcase_07 AC 103 ms
72,252 KB
testcase_08 AC 102 ms
72,516 KB
testcase_09 AC 102 ms
72,440 KB
testcase_10 AC 102 ms
72,536 KB
testcase_11 AC 102 ms
72,376 KB
testcase_12 AC 104 ms
72,424 KB
testcase_13 AC 104 ms
72,072 KB
testcase_14 AC 101 ms
72,444 KB
testcase_15 AC 104 ms
72,440 KB
testcase_16 AC 105 ms
72,440 KB
testcase_17 AC 102 ms
72,332 KB
testcase_18 AC 103 ms
72,316 KB
testcase_19 AC 104 ms
72,228 KB
testcase_20 AC 105 ms
72,316 KB
testcase_21 AC 102 ms
72,460 KB
testcase_22 AC 257 ms
89,460 KB
testcase_23 AC 233 ms
89,588 KB
testcase_24 AC 296 ms
96,560 KB
testcase_25 AC 299 ms
96,632 KB
testcase_26 AC 238 ms
90,548 KB
testcase_27 AC 237 ms
90,096 KB
testcase_28 AC 374 ms
99,536 KB
testcase_29 AC 379 ms
99,132 KB
testcase_30 AC 354 ms
96,816 KB
testcase_31 AC 359 ms
97,688 KB
testcase_32 AC 368 ms
97,308 KB
testcase_33 AC 403 ms
98,592 KB
testcase_34 AC 378 ms
97,496 KB
testcase_35 AC 372 ms
97,724 KB
testcase_36 AC 410 ms
95,272 KB
testcase_37 AC 426 ms
94,068 KB
testcase_38 AC 441 ms
95,436 KB
testcase_39 AC 443 ms
95,432 KB
testcase_40 AC 449 ms
96,308 KB
権限があれば一括ダウンロードができます

ソースコード

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(maxsize=1000)
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