結果

問題 No.840 ほむほむほむら
ユーザー ryuhei1230ryuhei1230
提出日時 2019-08-20 00:31:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 809 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 50,932 KB
最終ジャッジ日時 2024-04-15 15:06:33
合計ジャッジ時間 9,794 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 529 ms
43,472 KB
testcase_01 AC 596 ms
43,624 KB
testcase_02 AC 1,235 ms
43,988 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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