結果

問題 No.840 ほむほむほむら
コンテスト
ユーザー ryuhei1230
提出日時 2019-08-20 00:31:58
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 809 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 58 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 35,112 KB
最終ジャッジ日時 2026-09-10 16:24:15
合計ジャッジ時間 26,855 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 4 WA * 7 TLE * 3 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import numpy as np
N, k = list(map(int, input().split()))
mod = 998244353
mat_len = k ** 3


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



B = np.zeros((mat_len, mat_len))
for i in range(k):
    for j in range(k):
        for l in range(k):
            cur = i*k*k+j*k+l
            B[i*k*k+j*k+(l+1)%k][cur] += 1
            B[i*k*k+(j+l)%k*k+l][cur] += 1
            B[(i+j)%k*k*k+j*k+l][cur] += 1



ans = np.identity(mat_len)


while N:
    if N & 1:
        ans = mul(ans, B)
    B=mul(B, B)
    N>>=1




ret = 0
for i in range(k**2):
    ret = (ret + ans[i][0])%mod



print(int(ret))
0