結果

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

ソースコード

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)
	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))
for i in range(k):
	pre[i][0] = 1
mat = np.zeros((k*k, k*k))
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 += int(res[i*k][0])
	ans %= MOD
print(ans)
0