結果

問題 No.1112 冥界の音楽
ユーザー neterukunneterukun
提出日時 2020-07-10 22:59:52
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 76,960 KB
最終ジャッジ日時 2023-08-01 22:19:03
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,560 KB
testcase_01 AC 72 ms
71,440 KB
testcase_02 AC 73 ms
71,112 KB
testcase_03 AC 71 ms
71,132 KB
testcase_04 AC 72 ms
71,264 KB
testcase_05 AC 73 ms
71,116 KB
testcase_06 AC 85 ms
76,600 KB
testcase_07 AC 72 ms
71,440 KB
testcase_08 AC 75 ms
75,676 KB
testcase_09 AC 79 ms
76,376 KB
testcase_10 AC 70 ms
71,256 KB
testcase_11 AC 80 ms
76,472 KB
testcase_12 AC 72 ms
71,440 KB
testcase_13 AC 84 ms
76,472 KB
testcase_14 AC 110 ms
76,528 KB
testcase_15 AC 89 ms
76,436 KB
testcase_16 AC 73 ms
71,440 KB
testcase_17 AC 90 ms
76,260 KB
testcase_18 AC 90 ms
76,480 KB
testcase_19 AC 74 ms
71,396 KB
testcase_20 AC 84 ms
76,288 KB
testcase_21 AC 109 ms
76,120 KB
testcase_22 AC 107 ms
76,512 KB
testcase_23 AC 88 ms
76,576 KB
testcase_24 AC 74 ms
71,456 KB
testcase_25 AC 72 ms
71,404 KB
testcase_26 AC 82 ms
76,392 KB
testcase_27 AC 81 ms
76,400 KB
testcase_28 AC 83 ms
76,372 KB
testcase_29 AC 72 ms
71,440 KB
testcase_30 AC 113 ms
76,724 KB
testcase_31 AC 81 ms
76,624 KB
testcase_32 AC 118 ms
76,508 KB
testcase_33 AC 82 ms
76,120 KB
testcase_34 AC 75 ms
71,376 KB
testcase_35 AC 83 ms
76,352 KB
testcase_36 AC 199 ms
76,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def _mul(A, B, MOD):
    C = [[0] * len(B[0]) for i 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 pow_matrix(A, n, MOD):
    """A**nをダブリングによって求める。"""
    B = [[0] * len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1:
            B = _mul(A, B, MOD)
        A = _mul(A, A, MOD)
        n  = n // 2
    return B

k, m, n = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
MOD = 10 ** 9 + 7

# matrix_l * a * matrix_r
matrix = [[0] * (k ** 2) for i in range(k ** 2)]
for p, q, r in info:
    p -= 1
    q -= 1
    r -= 1
    row = 0
    col = 0
    row += r * k
    row += q
    col += q * k
    col += p
    matrix[row][col] += 1
matrix = pow_matrix(matrix, n - 2, MOD)
ans = [0] * (k ** 2)
for i in range(k):
    ans[i * k] = 1

res = 0
for i in range(k):
    for j in range(k ** 2):
        res += matrix[i][j] * ans[j]
        res %= MOD
print(res)
0