結果

問題 No.762 PDCAパス
ユーザー yakeshibayakeshiba
提出日時 2020-11-01 02:11:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 88,560 KB
最終ジャッジ日時 2023-09-29 11:03:53
合計ジャッジ時間 8,169 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,656 KB
testcase_01 AC 90 ms
71,904 KB
testcase_02 AC 89 ms
71,320 KB
testcase_03 AC 89 ms
71,536 KB
testcase_04 AC 89 ms
71,816 KB
testcase_05 AC 89 ms
71,860 KB
testcase_06 AC 90 ms
71,880 KB
testcase_07 AC 90 ms
71,400 KB
testcase_08 AC 92 ms
71,796 KB
testcase_09 AC 89 ms
71,672 KB
testcase_10 AC 89 ms
71,652 KB
testcase_11 AC 88 ms
71,628 KB
testcase_12 AC 91 ms
71,464 KB
testcase_13 AC 89 ms
71,800 KB
testcase_14 AC 89 ms
71,672 KB
testcase_15 AC 92 ms
71,368 KB
testcase_16 AC 96 ms
71,816 KB
testcase_17 AC 92 ms
71,500 KB
testcase_18 AC 91 ms
71,824 KB
testcase_19 AC 90 ms
71,556 KB
testcase_20 AC 91 ms
71,616 KB
testcase_21 AC 90 ms
71,728 KB
testcase_22 AC 185 ms
78,624 KB
testcase_23 AC 181 ms
78,352 KB
testcase_24 AC 208 ms
88,400 KB
testcase_25 AC 206 ms
88,560 KB
testcase_26 AC 173 ms
78,696 KB
testcase_27 AC 176 ms
78,772 KB
testcase_28 AC 256 ms
86,876 KB
testcase_29 AC 248 ms
87,296 KB
testcase_30 AC 239 ms
85,508 KB
testcase_31 AC 245 ms
85,764 KB
testcase_32 AC 240 ms
85,524 KB
testcase_33 AC 230 ms
83,120 KB
testcase_34 AC 228 ms
82,984 KB
testcase_35 AC 235 ms
83,896 KB
testcase_36 AC 213 ms
80,380 KB
testcase_37 AC 208 ms
80,300 KB
testcase_38 AC 213 ms
80,408 KB
testcase_39 AC 210 ms
80,436 KB
testcase_40 AC 213 ms
80,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

mod = 10**9+7

n, m = map(int,input().split())

S = input()
ind = defaultdict(list)
for i, s in enumerate(S):
    ind[s].append(i)

edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(lambda x:int(x)-1,input().split())
    if (S[u] == "P" and S[v] == "D") or (S[u] == "D" and S[v] == "C") or (S[u] == "C" and S[v] == "A"):
        edge[u].append(v)
    elif (S[u] == "D" and S[v] == "P") or (S[u] == "C" and S[v] == "D") or (S[u] == "A" and S[v] == "C"):
        edge[v].append(u)

dp = [0]*n
for p in ind["P"]:
    dp[p] = 1
    for to in edge[p]:
        dp[to] += dp[p]

for d in ind["D"]:
    for to in edge[d]:
        dp[to] += dp[d]
        
for c in ind["C"]:
    for to in edge[c]:
        dp[to] += dp[c]
        
ans = 0
for key in ind["A"]:
    ans += dp[key]
    
print(ans%mod)
0