結果

問題 No.1112 冥界の音楽
ユーザー xuanjixuanji
提出日時 2020-07-10 23:14:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2024-04-19 23:37:56
合計ジャッジ時間 3,752 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
70,144 KB
testcase_01 AC 35 ms
52,224 KB
testcase_02 AC 34 ms
52,224 KB
testcase_03 AC 33 ms
52,096 KB
testcase_04 AC 36 ms
52,736 KB
testcase_05 AC 34 ms
52,480 KB
testcase_06 AC 63 ms
76,032 KB
testcase_07 AC 38 ms
52,096 KB
testcase_08 AC 42 ms
59,008 KB
testcase_09 AC 56 ms
67,328 KB
testcase_10 AC 35 ms
52,224 KB
testcase_11 AC 55 ms
71,296 KB
testcase_12 AC 37 ms
52,096 KB
testcase_13 AC 61 ms
72,320 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 36 ms
52,352 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 34 ms
52,224 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 35 ms
52,224 KB
testcase_25 AC 37 ms
52,736 KB
testcase_26 AC 54 ms
66,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 37 ms
52,992 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 56 ms
66,944 KB
testcase_34 AC 35 ms
52,864 KB
testcase_35 AC 57 ms
67,584 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

MODULUS = 10**9+7

class Mat(list):
    def __matmul__(self, B) :
        A = self
        return Mat([[sum(A[i][k]*B[k][j] for k in range(len(B))) % MODULUS
                    for j in range(len(B[0])) ] for i in range(len(A))])
 
def identity(size):
    size = range(size)
    return [[(i==j)*1 for i in size] for j in size]
 
def power(F, n):
    result = Mat(identity(len(F)))
    b = Mat(F)
    while n > 0:
        if (n%2) == 0:
            b = b @ b
            n //= 2
        else:
            result = b @ result
            b = b @ b
            n //= 2
    return result

K, M, N = input().split(' ')

K = int(K)
M = int(M)
N = int(N)

adjacency = []
for _ in range(K*K):
    row = [0]*(K*K)
    adjacency += [row]

for _ in range(M):
    P, Q, R = input().split(' ')
    P = int(P)
    Q = int(Q)
    R = int(R)

    P -= 1
    Q -= 1
    R -= 1

    adjacency[P*K + Q][Q*K+R] = 1

if N == 1: 
    print(1)
elif N == 2:
    print(adjacency[0][0])
else:
    adjacency = power(adjacency, N-2)

    ret = 0

    for p in [0]:
        for q in range(K):
            for r in range(K):
                for s in [0]:
                    ret += adjacency[p*K+q][r*K+s]
    
    print(ret)

0