結果

問題 No.762 PDCAパス
ユーザー htkbhtkb
提出日時 2019-02-18 14:18:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 28,144 KB
最終ジャッジ日時 2024-04-15 21:45:50
合計ジャッジ時間 7,652 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 29 ms
10,752 KB
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 27 ms
10,880 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 27 ms
10,752 KB
testcase_13 AC 28 ms
10,752 KB
testcase_14 AC 29 ms
10,752 KB
testcase_15 AC 27 ms
10,752 KB
testcase_16 AC 28 ms
10,752 KB
testcase_17 AC 28 ms
10,752 KB
testcase_18 AC 29 ms
10,752 KB
testcase_19 AC 29 ms
10,752 KB
testcase_20 AC 29 ms
10,752 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 172 ms
15,488 KB
testcase_23 AC 172 ms
15,488 KB
testcase_24 AC 299 ms
26,736 KB
testcase_25 AC 307 ms
26,860 KB
testcase_26 AC 187 ms
16,896 KB
testcase_27 AC 190 ms
16,896 KB
testcase_28 AC 318 ms
28,020 KB
testcase_29 AC 321 ms
28,144 KB
testcase_30 AC 306 ms
25,680 KB
testcase_31 AC 299 ms
25,676 KB
testcase_32 AC 357 ms
25,680 KB
testcase_33 AC 273 ms
23,320 KB
testcase_34 AC 280 ms
23,196 KB
testcase_35 AC 278 ms
23,316 KB
testcase_36 AC 231 ms
20,608 KB
testcase_37 AC 240 ms
20,736 KB
testcase_38 AC 232 ms
20,608 KB
testcase_39 AC 236 ms
20,736 KB
testcase_40 AC 244 ms
20,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

v_count, edge_count = map(int, input().split())
S = input()
edges = [[] for _ in [0]*v_count]
next_c = {"P":"D", "D":"C", "C":"A", "A":""}
mod = 10**9+7

for u, v in (map(int, l.split()) for l in sys.stdin):
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

dp = [-1]*v_count

def rec(v, c):
    if dp[v] == -1:
        _c = next_c[c]
        dp[v] = sum(rec(dest, _c)for dest in edges[v] if S[dest] == c) % mod
    return dp[v]


a_index = S.find("A")
while a_index != -1:
    dp[a_index] = 1
    a_index = S.find("A", a_index+1)

ans = 0
p_index = S.find("P")
while p_index != -1:
    ans += rec(p_index, "D")
    p_index = S.find("P", p_index+1)

print(ans % mod)
0