結果

問題 No.762 PDCAパス
ユーザー MIKI TakushiMIKI Takushi
提出日時 2018-12-16 23:56:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 25,856 KB
最終ジャッジ日時 2023-10-25 22:24:59
合計ジャッジ時間 9,964 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,180 KB
testcase_01 AC 27 ms
10,180 KB
testcase_02 AC 27 ms
10,180 KB
testcase_03 AC 27 ms
10,180 KB
testcase_04 AC 29 ms
10,180 KB
testcase_05 AC 29 ms
10,180 KB
testcase_06 AC 27 ms
10,180 KB
testcase_07 AC 27 ms
10,180 KB
testcase_08 AC 27 ms
10,180 KB
testcase_09 AC 27 ms
10,180 KB
testcase_10 AC 27 ms
10,180 KB
testcase_11 AC 31 ms
10,180 KB
testcase_12 AC 27 ms
10,180 KB
testcase_13 AC 27 ms
10,180 KB
testcase_14 AC 27 ms
10,180 KB
testcase_15 AC 27 ms
10,180 KB
testcase_16 AC 27 ms
10,180 KB
testcase_17 AC 27 ms
10,180 KB
testcase_18 AC 27 ms
10,180 KB
testcase_19 AC 27 ms
10,180 KB
testcase_20 AC 27 ms
10,180 KB
testcase_21 AC 27 ms
10,180 KB
testcase_22 AC 358 ms
11,116 KB
testcase_23 AC 359 ms
11,116 KB
testcase_24 AC 445 ms
25,856 KB
testcase_25 AC 436 ms
25,856 KB
testcase_26 AC 385 ms
13,072 KB
testcase_27 AC 388 ms
13,072 KB
testcase_28 AC 488 ms
23,260 KB
testcase_29 AC 493 ms
23,292 KB
testcase_30 AC 460 ms
20,304 KB
testcase_31 AC 460 ms
20,308 KB
testcase_32 AC 464 ms
20,320 KB
testcase_33 AC 438 ms
17,636 KB
testcase_34 AC 434 ms
17,648 KB
testcase_35 AC 425 ms
17,636 KB
testcase_36 AC 394 ms
13,444 KB
testcase_37 AC 394 ms
13,416 KB
testcase_38 AC 391 ms
13,416 KB
testcase_39 AC 397 ms
13,452 KB
testcase_40 AC 387 ms
13,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
n,m = map(int, input().split())
s = list(input())
edge = [[] for _ in range(n)]
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    if (s[u]=="P" and s[v]=="D" or
        s[u]=="D" and s[v]=="C" or
        s[u]=="C" and s[v]=="A"
    ):
        edge[u].append(v)

    if (s[v]=="P" and s[u]=="D" or
        s[v]=="D" and s[u]=="C" or
        s[v]=="C" and s[u]=="A"
    ):
        edge[v].append(u)

dp = [[0 for _ in range(n)] for _ in range(4)]

for i in range(n):
    if s[i]=="P":
        dp[0][i] = 1

for u in range(n):
    for v in edge[u]:
        if s[v]=="D":
            dp[1][v] += dp[0][u]

for u in range(n):
    for v in edge[u]:
        if s[v]=="C":
            dp[2][v] += dp[1][u]

for u in range(n):
    for v in edge[u]:
        if s[v]=="A":
            dp[3][v] += dp[2][u]

res = sum(dp[3])%(10**9 + 7)
print(res)
0