結果

問題 No.1112 冥界の音楽
ユーザー 👑 tamatotamato
提出日時 2020-07-10 21:53:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,166 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 77,096 KB
最終ジャッジ日時 2023-08-01 17:40:38
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,456 KB
testcase_01 AC 72 ms
71,640 KB
testcase_02 AC 72 ms
71,484 KB
testcase_03 AC 72 ms
71,596 KB
testcase_04 AC 72 ms
71,392 KB
testcase_05 AC 71 ms
71,272 KB
testcase_06 AC 82 ms
76,456 KB
testcase_07 AC 70 ms
71,396 KB
testcase_08 AC 74 ms
75,628 KB
testcase_09 AC 79 ms
76,384 KB
testcase_10 AC 71 ms
71,580 KB
testcase_11 AC 81 ms
76,196 KB
testcase_12 AC 70 ms
71,464 KB
testcase_13 AC 81 ms
76,360 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 72 ms
71,392 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 72 ms
71,264 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 83 ms
76,828 KB
testcase_24 AC 76 ms
71,400 KB
testcase_25 AC 72 ms
71,640 KB
testcase_26 AC 80 ms
76,360 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 72 ms
71,728 KB
testcase_30 WA -
testcase_31 AC 78 ms
76,512 KB
testcase_32 WA -
testcase_33 AC 81 ms
76,452 KB
testcase_34 AC 72 ms
71,472 KB
testcase_35 AC 80 ms
76,428 KB
testcase_36 AC 131 ms
77,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    def matpow(A, p):
        n = len(A)
        B = [[0] * n for _ in range(n)]
        for i in range(n):
            B[i][i] = 1
        while p > 0:
            if p & 1:
                B = matmul(B, A)
            A = matmul(A, A)
            p >>= 1
        return B

    K, M, N = map(int, input().split())
    T = []
    mat = [[0] * (K*K) for _ in range(K*K)]
    for _ in range(M):
        p, q, r = map(int, input().split())
        p -= 1
        q -= 1
        r -= 1
        pre = p + q * K
        post = q + r * K
        mat[post][pre] = 1
    vec = [[0] for _ in range(K*K)]
    for i in range(K):
        vec[i*K][0] = 1
    vec2 = matmul(matpow(mat, N-2), vec)
    ans = 0
    for i in range(K):
        ans = (ans + vec2[i][0])
    print(ans)


if __name__ == '__main__':
    main()
0