結果

問題 No.762 PDCAパス
ユーザー Konton7
提出日時 2019-05-15 23:24:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-09-14 16:06:40
合計ジャッジ時間 10,950 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = [ int(v) for v in input().split() ]
s = input()

mod = 1000000007

dlist= [ 0 for i in range(n) ]
clist= [ 0 for i in range(n) ]
dclist = []

for i in range(m):
    x, y = [ int(v) for v in input().split() ]
    if s[x-1] == "P" and s[y-1] == "D":
        dlist[y-1] += 1
        
    elif s[x-1] == "D" and s[y-1] == "P":
        dlist[x-1] += 1

    elif s[x-1] == "D" and s[y-1] == "C":
        dclist.append([x-1,y-1])

    elif s[x-1] == "C" and s[y-1] == "D":
        dclist.append([y-1,x-1])

    elif s[x-1] == "C" and s[y-1] == "A":
        clist[x-1] += 1

    elif s[x-1] == "A" and s[y-1] == "C":
        clist[y-1] += 1



s = 0
for i in dclist:
    s += (dlist[i[0]]*clist[i[1]]) 

ans = s % mod
print(ans)
0