結果

問題 No.1112 冥界の音楽
ユーザー ayaoniayaoni
提出日時 2020-11-29 23:21:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,076 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 78,744 KB
最終ジャッジ日時 2023-10-11 02:40:25
合計ジャッジ時間 6,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,788 KB
testcase_01 AC 74 ms
71,408 KB
testcase_02 AC 71 ms
71,368 KB
testcase_03 AC 73 ms
71,656 KB
testcase_04 AC 73 ms
71,168 KB
testcase_05 AC 73 ms
71,576 KB
testcase_06 AC 107 ms
77,572 KB
testcase_07 AC 72 ms
71,276 KB
testcase_08 AC 77 ms
75,856 KB
testcase_09 AC 89 ms
76,824 KB
testcase_10 AC 71 ms
71,632 KB
testcase_11 AC 93 ms
76,596 KB
testcase_12 AC 73 ms
71,516 KB
testcase_13 AC 104 ms
77,912 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 72 ms
71,176 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 72 ms
71,320 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 72 ms
71,424 KB
testcase_25 AC 73 ms
71,520 KB
testcase_26 AC 92 ms
76,820 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 71 ms
71,448 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 91 ms
76,824 KB
testcase_34 AC 73 ms
71,444 KB
testcase_35 AC 93 ms
76,496 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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