結果

問題 No.1112 冥界の音楽
コンテスト
ユーザー ああ
提出日時 2026-05-19 21:33:17
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 64 ms / 2,000 ms
+ 562µs
コード長 746 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 86 ms
コンパイル使用メモリ 83,200 KB
実行使用メモリ 76,824 KB
最終ジャッジ日時 2026-09-29 19:04:04
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_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