結果

問題 No.1112 冥界の音楽
ユーザー SSlime
提出日時 2020-07-11 09:56:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 93,560 KB
最終ジャッジ日時 2024-10-12 17:43:43
合計ジャッジ時間 24,500 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 11 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

k, m, n = map(int, input().split())
P = [tuple(map(int, input().split())) for i in range(m)]

X = np.array([[0] * m for i in range(m)])

A = np.array([[0] for i in range(m)])
end = []
for i,(p,q,r) in enumerate(P):
    for j in range(m):
        if P[j][0] == q and P[j][1] == r:
            X[j][i] += 1
    if p == 1:
        A[i][0] += 1
    if r == 1:
        end.append(i)
mod = 10**9 + 7
n -= 3
res = np.array([[0]*i + [1] + [0]*(m-i-1) for i in range(m)])
while n > 0:
    if n & 1:
        res = np.dot(X, res) % mod
    X = np.dot(X, X) % mod
    n >>= 1

B = np.dot(res, A) % mod
ans = 0
for i in end:
    ans += B[i][0]
    ans %= mod
print(ans)
0