結果

問題 No.1112 冥界の音楽
ユーザー convexineqconvexineq
提出日時 2021-05-11 02:34:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 75,296 KB
最終ジャッジ日時 2023-10-21 07:34:41
合計ジャッジ時間 5,157 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
61,656 KB
testcase_01 AC 41 ms
59,608 KB
testcase_02 AC 44 ms
61,792 KB
testcase_03 AC 40 ms
59,608 KB
testcase_04 AC 42 ms
61,656 KB
testcase_05 AC 44 ms
61,656 KB
testcase_06 AC 43 ms
61,656 KB
testcase_07 AC 40 ms
59,608 KB
testcase_08 AC 40 ms
59,608 KB
testcase_09 AC 42 ms
61,656 KB
testcase_10 AC 43 ms
61,656 KB
testcase_11 AC 43 ms
61,656 KB
testcase_12 AC 40 ms
61,656 KB
testcase_13 AC 45 ms
61,656 KB
testcase_14 AC 50 ms
65,888 KB
testcase_15 AC 49 ms
63,840 KB
testcase_16 AC 49 ms
63,840 KB
testcase_17 AC 50 ms
65,888 KB
testcase_18 AC 48 ms
63,840 KB
testcase_19 AC 50 ms
63,840 KB
testcase_20 AC 48 ms
63,840 KB
testcase_21 AC 46 ms
63,840 KB
testcase_22 AC 49 ms
63,840 KB
testcase_23 AC 51 ms
63,840 KB
testcase_24 AC 67 ms
75,284 KB
testcase_25 AC 68 ms
75,280 KB
testcase_26 AC 62 ms
73,248 KB
testcase_27 AC 59 ms
72,400 KB
testcase_28 AC 66 ms
75,284 KB
testcase_29 AC 63 ms
73,380 KB
testcase_30 AC 63 ms
72,824 KB
testcase_31 AC 60 ms
72,588 KB
testcase_32 AC 69 ms
75,272 KB
testcase_33 AC 63 ms
73,532 KB
testcase_34 AC 64 ms
72,528 KB
testcase_35 AC 65 ms
73,672 KB
testcase_36 AC 71 ms
75,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0]*len(B[0]) for _ in [None]*len(A)]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] += aik*bkj
                resi[j] %= MOD
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[int(i==j) for j in range(len(A))] for i in range(len(A))]

MOD = 10**9+7
S = 36
k,m,n = map(int,input().split())
A = [[0]*S for _ in range(S)]
for _ in range(m):
    p,q,r = map(int,input().split())
    A[(p-1)*6+q-1][(q-1)*6+r-1] += 1

v = [0]*S
v[:6] = [1]*6
v = matmul([v],matpow(A,n-2))
print(sum(v[0][0:S:6])%MOD)
0