結果

問題 No.840 ほむほむほむら
ユーザー convexineqconvexineq
提出日時 2021-04-03 15:22:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 405 ms / 4,000 ms
コード長 942 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 80,852 KB
最終ジャッジ日時 2023-08-26 06:10:13
合計ジャッジ時間 6,448 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,116 KB
testcase_01 AC 69 ms
75,840 KB
testcase_02 AC 76 ms
76,316 KB
testcase_03 AC 105 ms
76,268 KB
testcase_04 AC 75 ms
76,116 KB
testcase_05 AC 70 ms
76,132 KB
testcase_06 AC 70 ms
75,964 KB
testcase_07 AC 85 ms
76,248 KB
testcase_08 AC 146 ms
77,128 KB
testcase_09 AC 74 ms
75,992 KB
testcase_10 AC 72 ms
76,008 KB
testcase_11 AC 71 ms
76,036 KB
testcase_12 AC 98 ms
76,212 KB
testcase_13 AC 277 ms
78,268 KB
testcase_14 AC 102 ms
77,100 KB
testcase_15 AC 74 ms
76,040 KB
testcase_16 AC 79 ms
76,272 KB
testcase_17 AC 123 ms
77,052 KB
testcase_18 AC 336 ms
80,852 KB
testcase_19 AC 405 ms
79,664 KB
testcase_20 AC 68 ms
71,300 KB
testcase_21 AC 68 ms
76,088 KB
testcase_22 AC 77 ms
76,264 KB
testcase_23 AC 386 ms
79,772 KB
testcase_24 AC 77 ms
75,952 KB
testcase_25 AC 67 ms
75,988 KB
testcase_26 AC 79 ms
76,280 KB
testcase_27 AC 379 ms
79,348 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 [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]

n,k = map(int,input().split())
MOD = 998244353
pk = [k**i for i in range(4)]
A = [[0]*pk[3] for _ in range(pk[3])]
from itertools import product
for q,r,s in product(range(k),repeat=3):
    v = q*pk[2] + r*pk[1] + s
    for qq,rr,ss in [((1+q)%k,r,s),(q,(q+r)%k,s),(q,r,(r+s)%k)]:
        w = qq*pk[2] + rr*pk[1] + ss
        A[w][v] += 1

v = [[0]*pk[3]]
v[0][0] = 1
v = matmul(v,matpow(A,n))
print(sum(v[0][::k])%MOD)
0