結果

問題 No.762 PDCAパス
ユーザー lloyzlloyz
提出日時 2023-05-10 00:08:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 91,860 KB
最終ジャッジ日時 2023-08-17 12:07:38
合計ジャッジ時間 10,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,372 KB
testcase_01 AC 96 ms
71,620 KB
testcase_02 AC 93 ms
71,336 KB
testcase_03 AC 94 ms
71,236 KB
testcase_04 AC 93 ms
71,560 KB
testcase_05 AC 95 ms
71,660 KB
testcase_06 AC 93 ms
71,584 KB
testcase_07 AC 96 ms
71,432 KB
testcase_08 AC 95 ms
71,564 KB
testcase_09 AC 94 ms
71,592 KB
testcase_10 AC 96 ms
71,292 KB
testcase_11 AC 98 ms
71,584 KB
testcase_12 AC 98 ms
71,480 KB
testcase_13 AC 94 ms
71,520 KB
testcase_14 AC 92 ms
71,608 KB
testcase_15 AC 93 ms
71,548 KB
testcase_16 AC 95 ms
71,376 KB
testcase_17 AC 94 ms
71,588 KB
testcase_18 AC 94 ms
71,580 KB
testcase_19 AC 93 ms
71,684 KB
testcase_20 AC 94 ms
71,688 KB
testcase_21 AC 95 ms
71,576 KB
testcase_22 AC 199 ms
78,248 KB
testcase_23 AC 190 ms
78,524 KB
testcase_24 AC 251 ms
90,664 KB
testcase_25 AC 241 ms
90,972 KB
testcase_26 AC 185 ms
78,956 KB
testcase_27 AC 185 ms
78,812 KB
testcase_28 AC 261 ms
91,848 KB
testcase_29 AC 259 ms
91,860 KB
testcase_30 AC 252 ms
88,104 KB
testcase_31 AC 252 ms
87,996 KB
testcase_32 AC 258 ms
87,988 KB
testcase_33 AC 247 ms
84,320 KB
testcase_34 AC 245 ms
85,144 KB
testcase_35 AC 245 ms
84,168 KB
testcase_36 AC 236 ms
80,376 KB
testcase_37 AC 240 ms
80,484 KB
testcase_38 AC 241 ms
80,504 KB
testcase_39 AC 237 ms
80,232 KB
testcase_40 AC 234 ms
80,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, m = map(int, input().split())
s = input()
G = defaultdict(list)
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if s[u] == 'P' and s[v] == 'D':
        G[v].append(u)
    elif s[u] == 'D' and s[v] == 'P':
        G[u].append(v)
    elif s[u] == 'D' and s[v] == 'C':
        G[v].append(u)
    elif s[v] == 'D' and s[u] == 'C':
        G[u].append(v)
    elif s[u] == 'C' and s[v] == 'A':
        G[v].append(u)
    elif s[u] == 'A' and s[v] == 'C':
        G[u].append(v)
mod = 10**9 + 7

DP = [0 for _ in range(n)]
for ss in ['A', 'C', 'D']:
    for i in range(n):
        if s[i] == ss:
            if ss == 'A':
                DP[i] = 1
            for j in G[i]:
                DP[j] += DP[i]
                DP[j] %= mod
ans = 0
for i in range(n):
    if s[i] == 'P':
        ans += DP[i]
        ans %= mod
print(ans)
0