結果

問題 No.762 PDCAパス
ユーザー matsu7874matsu7874
提出日時 2018-11-28 01:47:28
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 29,652 KB
最終ジャッジ日時 2023-09-07 07:51:48
合計ジャッジ時間 11,361 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,808 KB
testcase_01 AC 16 ms
7,856 KB
testcase_02 AC 17 ms
7,920 KB
testcase_03 AC 16 ms
7,932 KB
testcase_04 AC 15 ms
7,872 KB
testcase_05 AC 16 ms
7,928 KB
testcase_06 AC 16 ms
7,792 KB
testcase_07 AC 16 ms
7,812 KB
testcase_08 AC 17 ms
7,952 KB
testcase_09 AC 16 ms
7,864 KB
testcase_10 AC 16 ms
7,756 KB
testcase_11 AC 17 ms
7,764 KB
testcase_12 AC 16 ms
7,772 KB
testcase_13 AC 16 ms
7,840 KB
testcase_14 AC 16 ms
7,920 KB
testcase_15 AC 16 ms
7,928 KB
testcase_16 AC 16 ms
7,768 KB
testcase_17 AC 17 ms
7,764 KB
testcase_18 AC 16 ms
7,848 KB
testcase_19 AC 16 ms
7,768 KB
testcase_20 AC 16 ms
7,776 KB
testcase_21 AC 16 ms
7,872 KB
testcase_22 AC 332 ms
12,736 KB
testcase_23 AC 337 ms
12,888 KB
testcase_24 AC 443 ms
28,316 KB
testcase_25 AC 444 ms
28,312 KB
testcase_26 AC 368 ms
14,280 KB
testcase_27 AC 364 ms
14,156 KB
testcase_28 AC 542 ms
29,652 KB
testcase_29 AC 543 ms
29,608 KB
testcase_30 AC 526 ms
26,488 KB
testcase_31 AC 523 ms
26,192 KB
testcase_32 AC 513 ms
26,280 KB
testcase_33 AC 488 ms
22,784 KB
testcase_34 AC 483 ms
22,684 KB
testcase_35 AC 483 ms
22,748 KB
testcase_36 AC 420 ms
18,712 KB
testcase_37 AC 423 ms
18,632 KB
testcase_38 AC 433 ms
18,728 KB
testcase_39 AC 422 ms
18,772 KB
testcase_40 AC 427 ms
18,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7

n, m = map(int, input().split())
assert 2 <= n <= 10**5
assert 0 <= m <= 10**5

s = input()
assert len(s) == n
assert all(c in 'PCDA' for c in s)

graph = [[] for i in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    assert 1 <= u < v <= n
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)


nodes = {c: [] for c in 'PDCA'}
pre = {
    'D': 'P',
    'C': 'D',
    'A': 'C',
}
for i in range(n):
    nodes[s[i]].append(i)


cnt = [1 if s[i] == 'P' else 0 for i in range(n)]
for c in 'DCA':
    for v in nodes[c]:
        for u in graph[v]:
            if s[u] == pre[c]:
                cnt[v] += cnt[u]
                cnt[v] %= mod
print(sum([cnt[v] for v in nodes['A']]) % mod)
0