結果
問題 | No.762 PDCAパス |
ユーザー |
![]() |
提出日時 | 2019-02-18 14:18:16 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 341 ms / 2,000 ms |
コード長 | 712 bytes |
コンパイル時間 | 114 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 28,024 KB |
最終ジャッジ日時 | 2024-10-06 03:13:51 |
合計ジャッジ時間 | 8,066 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import syssys.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+7for 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_countdef 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) % modreturn dp[v]a_index = S.find("A")while a_index != -1:dp[a_index] = 1a_index = S.find("A", a_index+1)ans = 0p_index = S.find("P")while p_index != -1:ans += rec(p_index, "D")p_index = S.find("P", p_index+1)print(ans % mod)