結果

問題 No.762 PDCAパス
ユーザー matsu7874matsu7874
提出日時 2018-11-28 01:59:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 29,600 KB
最終ジャッジ日時 2023-09-07 08:19:21
合計ジャッジ時間 14,304 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,020 KB
testcase_01 AC 17 ms
7,972 KB
testcase_02 AC 16 ms
8,068 KB
testcase_03 AC 16 ms
7,824 KB
testcase_04 AC 16 ms
8,060 KB
testcase_05 AC 17 ms
7,912 KB
testcase_06 AC 18 ms
8,100 KB
testcase_07 AC 16 ms
7,968 KB
testcase_08 AC 16 ms
7,924 KB
testcase_09 AC 16 ms
7,956 KB
testcase_10 AC 16 ms
7,940 KB
testcase_11 AC 16 ms
7,900 KB
testcase_12 AC 16 ms
7,824 KB
testcase_13 AC 16 ms
8,092 KB
testcase_14 AC 16 ms
7,828 KB
testcase_15 AC 16 ms
8,020 KB
testcase_16 AC 17 ms
7,880 KB
testcase_17 AC 16 ms
8,032 KB
testcase_18 AC 16 ms
8,092 KB
testcase_19 AC 16 ms
8,000 KB
testcase_20 AC 16 ms
7,916 KB
testcase_21 AC 16 ms
7,852 KB
testcase_22 AC 970 ms
12,860 KB
testcase_23 AC 975 ms
12,816 KB
testcase_24 AC 457 ms
28,404 KB
testcase_25 AC 453 ms
28,456 KB
testcase_26 AC 846 ms
14,340 KB
testcase_27 AC 846 ms
14,344 KB
testcase_28 AC 584 ms
29,600 KB
testcase_29 AC 587 ms
29,592 KB
testcase_30 AC 569 ms
26,176 KB
testcase_31 AC 563 ms
26,184 KB
testcase_32 AC 569 ms
26,248 KB
testcase_33 AC 555 ms
22,796 KB
testcase_34 AC 557 ms
22,696 KB
testcase_35 AC 554 ms
22,880 KB
testcase_36 AC 561 ms
18,648 KB
testcase_37 AC 550 ms
18,764 KB
testcase_38 AC 546 ms
18,744 KB
testcase_39 AC 556 ms
18,556 KB
testcase_40 AC 558 ms
18,588 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
    assert (v-1) not in graph[u-1]
    assert (u-1) not in graph[v-1]
    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