結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー Kiri8128Kiri8128
提出日時 2021-05-21 23:03:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,259 ms / 6,000 ms
コード長 1,475 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-18 16:37:15
合計ジャッジ時間 7,783 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,608 KB
testcase_01 AC 91 ms
65,664 KB
testcase_02 AC 558 ms
78,848 KB
testcase_03 AC 43 ms
59,776 KB
testcase_04 AC 42 ms
59,264 KB
testcase_05 AC 45 ms
61,264 KB
testcase_06 AC 62 ms
65,152 KB
testcase_07 AC 111 ms
70,272 KB
testcase_08 AC 161 ms
76,416 KB
testcase_09 AC 43 ms
58,880 KB
testcase_10 AC 61 ms
63,232 KB
testcase_11 AC 45 ms
59,776 KB
testcase_12 AC 44 ms
59,264 KB
testcase_13 AC 44 ms
58,752 KB
testcase_14 AC 1,095 ms
83,072 KB
testcase_15 AC 536 ms
79,104 KB
testcase_16 AC 290 ms
77,312 KB
testcase_17 AC 135 ms
76,928 KB
testcase_18 AC 68 ms
68,992 KB
testcase_19 AC 54 ms
64,896 KB
testcase_20 AC 1,259 ms
82,900 KB
testcase_21 AC 1,246 ms
82,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mmult(A, B):
    global mod
    n, m, l = len(A), len(B), len(B[0])
    ret = [[0] * l for _ in range(n)]
    for i in range(n):
        reti = ret[i]
        Ai = A[i]
        for j in range(m):
            Aij = Ai[j]
            Bj = B[j]
            for k, b in enumerate(Bj):
                reti[k] = (reti[k] + Aij * b) % mod
    return ret
def mpow(A, n):
    if n == 1: return A
    if n == 0: return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]
    return mmult(mpow(A, n - 1), A) if n % 2 else mpow(mmult(A, A), n // 2)

mod = 998244353

P = 998244353
N, K = map(int, input().split())
KK = K ** 2
L = 2 * KK
M = [[0] * L for _ in range(L)]
A = [0] * L

X = [[1] * (K + 1) for _ in range(K)]
for i in range(K):
    for j in range(K):
        if i == j: continue
        A[i*K+j] = 1
        A[i*K+j+KK] = i + j

for i in range(K):
    for j in range(i):
        ij = i * K + j
        ij_ = ij + KK
        for k in range(j+1, K):
            if k == i: continue
            jk = j * K + k
            jk_ = jk + KK
            M[ij][jk] = 1
            M[ij_][jk_] = 1
            M[ij][jk_] = k
    for j in range(i+1, K):
        ij = i * K + j
        ij_ = ij + KK
        for k in range(j):
            if k == i: continue
            jk = j * K + k
            jk_ = jk + KK
            M[ij][jk] = 1
            M[ij_][jk_] = 1
            M[ij][jk_] = k

a = mmult([A], mpow(M, N - 2))[0]
print(sum(a[:KK]) % P, sum(a[KK:]) % P)
0