結果

問題 No.1112 冥界の音楽
コンテスト
ユーザー ああ
提出日時 2026-05-19 21:33:17
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 746 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 204 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 74,240 KB
最終ジャッジ日時 2026-05-19 21:33:23
合計ジャッジ時間 3,673 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def aa(mat,n):
    global k,mod
    ans=[[0]*k**2 for i in range(k**2)]
    for i in range(k):
        ans[0][i]=1
    while n:
        if n&1:
            ans=bb(ans,mat)
        n>>=1;mat=bb(mat,mat)
    res=0
    for i in range(k):
        for j in range(k):
            res+=ans[i][j*k]
    print(res%mod)
def bb(q,w):
    global k,mod
    res=[[0]*k**2 for i in range(k**2)]
    for i in range(k**2):
        for j in range(k**2):
            for l in range(k**2):
                res[j][l]+=q[j][i]*w[i][l]%mod
                res[j][l]%=mod
    return res


k,m,n=map(int,input().split());mod=10**9+7
mat=[[0]*k**2 for i in range(k**2)]
for i in range(m):
    a,b,c=map(int,input().split())
    mat[(a-1)*k+b-1][(b-1)*k+c-1]+=1
aa(mat,n-2)
0