結果

問題 No.1112 冥界の音楽
ユーザー ayaoniayaoni
提出日時 2020-11-29 23:22:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 78,360 KB
最終ジャッジ日時 2023-10-11 02:40:32
合計ジャッジ時間 5,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,840 KB
testcase_01 AC 72 ms
71,368 KB
testcase_02 AC 72 ms
71,212 KB
testcase_03 AC 73 ms
71,424 KB
testcase_04 AC 73 ms
71,580 KB
testcase_05 AC 71 ms
71,448 KB
testcase_06 AC 105 ms
77,660 KB
testcase_07 AC 73 ms
71,564 KB
testcase_08 AC 80 ms
75,844 KB
testcase_09 AC 92 ms
76,824 KB
testcase_10 AC 79 ms
71,596 KB
testcase_11 AC 92 ms
77,140 KB
testcase_12 AC 73 ms
71,328 KB
testcase_13 AC 105 ms
77,776 KB
testcase_14 AC 145 ms
77,620 KB
testcase_15 AC 105 ms
77,344 KB
testcase_16 AC 72 ms
71,316 KB
testcase_17 AC 107 ms
77,496 KB
testcase_18 AC 110 ms
77,224 KB
testcase_19 AC 72 ms
71,428 KB
testcase_20 AC 101 ms
77,740 KB
testcase_21 AC 143 ms
77,748 KB
testcase_22 AC 143 ms
77,812 KB
testcase_23 AC 105 ms
77,452 KB
testcase_24 AC 72 ms
71,428 KB
testcase_25 AC 73 ms
71,652 KB
testcase_26 AC 92 ms
76,760 KB
testcase_27 AC 92 ms
76,780 KB
testcase_28 AC 99 ms
77,484 KB
testcase_29 AC 74 ms
71,424 KB
testcase_30 AC 150 ms
77,624 KB
testcase_31 AC 97 ms
77,472 KB
testcase_32 AC 152 ms
77,424 KB
testcase_33 AC 92 ms
76,876 KB
testcase_34 AC 73 ms
71,376 KB
testcase_35 AC 92 ms
76,560 KB
testcase_36 AC 276 ms
78,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


def matrix_multiplication_mod(A,B,p):
    l = len(A)
    m = len(B)
    n = len(B[0])
    C = [[0]*n for _ in range(l)]
    for i in range(l):
        for j in range(n):
            C[i][j] = sum((A[i][k]*B[k][j]) % p for k in range(m)) % p
    return C


def matrix_power_mod(A,n,p):
    l = len(A)
    C = [[0] * l for _ in range(l)]
    for i in range(l):
        C[i][i] = 1
    while n > 0:
        if n % 2 == 1:
            C = matrix_multiplication_mod(C,A,p)
        A = matrix_multiplication_mod(A,A,p)
        n >>= 1
    return C


K,M,N = MI()
mod = 10**9+7
PQR = set([tuple(MI()) for _ in range(M)])

A = [[0]*(K**2) for _ in range(K**2)]
for i in range(K**2):
    i0,i1 = divmod(i,K)
    for j in range(K**2):
        j0,j1 = divmod(j,K)
        if i0 != j1:
            continue
        if (j0+1,i0+1,i1+1) in PQR:
            A[i][j] = 1

X = matrix_power_mod(A,N-2,mod)

ans = 0
for i in range(0,K**2,K):
    for j in range(K):
        ans += X[i][j]
        ans %= mod

print(ans)
0