結果

問題 No.1112 冥界の音楽
ユーザー H3PO4H3PO4
提出日時 2023-06-17 20:19:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 32,524 KB
最終ジャッジ日時 2023-09-07 16:19:07
合計ジャッジ時間 11,189 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,720 KB
testcase_01 AC 134 ms
29,696 KB
testcase_02 AC 140 ms
29,580 KB
testcase_03 AC 134 ms
29,672 KB
testcase_04 AC 139 ms
29,544 KB
testcase_05 AC 138 ms
29,628 KB
testcase_06 AC 137 ms
29,660 KB
testcase_07 AC 134 ms
29,612 KB
testcase_08 AC 134 ms
29,656 KB
testcase_09 AC 136 ms
29,628 KB
testcase_10 AC 137 ms
29,568 KB
testcase_11 AC 142 ms
29,544 KB
testcase_12 AC 141 ms
29,676 KB
testcase_13 AC 137 ms
29,704 KB
testcase_14 AC 207 ms
30,392 KB
testcase_15 AC 173 ms
29,848 KB
testcase_16 AC 166 ms
29,820 KB
testcase_17 AC 184 ms
30,064 KB
testcase_18 AC 187 ms
30,164 KB
testcase_19 AC 162 ms
29,688 KB
testcase_20 AC 169 ms
29,792 KB
testcase_21 AC 200 ms
30,376 KB
testcase_22 AC 202 ms
30,408 KB
testcase_23 AC 168 ms
29,932 KB
testcase_24 AC 258 ms
30,196 KB
testcase_25 AC 254 ms
30,000 KB
testcase_26 AC 242 ms
29,984 KB
testcase_27 AC 237 ms
30,204 KB
testcase_28 AC 256 ms
30,228 KB
testcase_29 AC 244 ms
30,032 KB
testcase_30 AC 302 ms
31,072 KB
testcase_31 AC 239 ms
30,120 KB
testcase_32 AC 316 ms
30,972 KB
testcase_33 AC 245 ms
29,980 KB
testcase_34 AC 235 ms
30,020 KB
testcase_35 AC 244 ms
30,260 KB
testcase_36 AC 440 ms
32,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 10 ** 9 + 7
int1 = lambda x: int(x) - 1


def pow_matrix_mod(x, n, mod=MOD):
    x = x.astype(object)
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


K, M, N = map(int, input().split())
matr = np.zeros((36, 36), dtype=int)
for _ in range(M):
    P, Q, R = map(int1, input().split())
    matr[6 * P + Q, 6 * Q + R] = True

A = np.zeros(36, dtype=object)
A[:6] = 1
print((A @ pow_matrix_mod(matr, N - 2))[::6].sum() % MOD)
0