結果

問題 No.1112 冥界の音楽
ユーザー anagohirame
提出日時 2020-07-10 23:37:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 661 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,752 KB
最終ジャッジ日時 2024-10-11 19:19:14
合計ジャッジ時間 22,480 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
import sys
def input():
	return sys.stdin.readline()[:-1]

MOD = 10**9+7

def mat_pow(mat, exp):
	size = len(mat)
	res = np.eye(size, dtype=np.object)
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = res @ mat
			res %= MOD
		mat = mat @ mat
		mat %= MOD
		cnt += 1
	return res

k, m, n = map(int, input().split())
pre = np.zeros((k*k, 1), dtype=np.object)
for i in range(k):
	pre[i][0] = 1
mat = np.zeros((k*k, k*k), dtype=np.object)
for _ in range(m):
	p, q, r = map(int, input().split())
	mat[(q-1)*k + r-1][(p-1)*k + q-1] += 1
res = mat_pow(mat, n-2) @ pre
ans = 0
for i in range(k):
	ans += res[i*k][0]
	ans %= MOD
print(ans)
0