結果

問題 No.1112 冥界の音楽
ユーザー roarisroaris
提出日時 2020-07-10 22:12:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 86,400 KB
最終ジャッジ日時 2024-04-19 20:58:24
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
73,984 KB
testcase_01 AC 40 ms
54,016 KB
testcase_02 AC 40 ms
53,888 KB
testcase_03 AC 41 ms
53,504 KB
testcase_04 AC 47 ms
61,696 KB
testcase_05 AC 47 ms
61,312 KB
testcase_06 AC 587 ms
77,824 KB
testcase_07 AC 40 ms
54,144 KB
testcase_08 AC 41 ms
54,272 KB
testcase_09 AC 92 ms
65,664 KB
testcase_10 AC 47 ms
61,312 KB
testcase_11 AC 161 ms
69,760 KB
testcase_12 AC 46 ms
61,312 KB
testcase_13 AC 41 ms
54,016 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def mat_mul(A, B):
    C = [[0]*len(B[0]) for _ in range(len(A))]
    
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(A[0])):
                C[i][j] += A[i][k]*B[k][j]
                C[i][j] %= MOD
    
    return C

def mat_pow(A, n):
    res = [[0]*len(A) for _ in range(len(A))]
    
    for i in range(len(A)):
        res[i][i] = 1
    
    while n>0:
        if n&1:
            res = mat_mul(res, A)
        
        n >>= 1
        A = mat_mul(A, A)
    
    return res

K, M, N = map(int, input().split())
MOD = 10**9+7

if N==3:
    ans = 0
    
    for _ in range(M):
        P, Q, R = map(int, input().split())
        
        if P==1 and R==1:
            ans += 1
    
    print(ans)
    exit()
    
serial = [[[-1]*K for _ in range(K)] for _ in range(K)]
c = 0

for i in range(K):
    for j in range(K):
        for k in range(K):
            serial[i][j][k] = c
            c += 1

A = [[0]*c for _ in range(c)]
ok = [False]*c

for _ in range(M):
    P, Q, R = map(int, input().split())
    ok[serial[P-1][Q-1][R-1]] = True

for i in range(K):
    for j in range(K):
        for k in range(K):
            for l in range(K):
                if ok[serial[i][j][k]] and ok[serial[j][k][l]]:
                    A[serial[i][j][k]][serial[j][k][l]] = 1

res = mat_pow(A, N-3)
ans = 0

for i in range(K):
    for j in range(K):
        for k in range(K):
            for l in range(K):
                ans += res[serial[0][i][j]][serial[k][l][0]]
                ans %= MOD

print(ans)
0