結果

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

ソースコード

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