結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-24 22:07:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 383 ms / 6,000 ms
コード長 1,169 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 76,196 KB
最終ジャッジ日時 2024-04-21 07:38:08
合計ジャッジ時間 4,351 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
58,624 KB
testcase_01 AC 76 ms
64,256 KB
testcase_02 AC 198 ms
76,160 KB
testcase_03 AC 50 ms
60,544 KB
testcase_04 AC 50 ms
60,800 KB
testcase_05 AC 52 ms
61,644 KB
testcase_06 AC 59 ms
62,720 KB
testcase_07 AC 76 ms
64,512 KB
testcase_08 AC 89 ms
66,176 KB
testcase_09 AC 49 ms
58,496 KB
testcase_10 AC 62 ms
62,592 KB
testcase_11 AC 50 ms
59,776 KB
testcase_12 AC 51 ms
60,416 KB
testcase_13 AC 50 ms
60,032 KB
testcase_14 AC 366 ms
75,904 KB
testcase_15 AC 201 ms
76,032 KB
testcase_16 AC 122 ms
73,344 KB
testcase_17 AC 81 ms
67,712 KB
testcase_18 AC 59 ms
62,720 KB
testcase_19 AC 60 ms
65,024 KB
testcase_20 AC 383 ms
76,180 KB
testcase_21 AC 375 ms
76,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
mod = 998244353


def mat_mul(A, B):
    res = [[0] * len(B[0]) for _ in range(len(A))]
    for i in range(len(A)):
        for k in range(len(A[0])):
            for j in range(len(B[0])):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res


def mat_pow(A, n):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res


A = [[0]*(K*K) for _ in range(K*K)]
B = [0] * (K*K)
for x in range(K):
    for y in range(K):
        if x == y:
            continue
        if x < y:
            for z in range(y):
                if x != z:
                    A[x*K+y][y*K+z] = 1
        if x > y:
            for z in range(y+1, K):
                if x != z:
                    A[x*K+y][y*K+z] = 1
        B[x*K+y] = 1

P = mat_pow(A, N-2)
ans1 = 0
for i in range(K*K):
    for j in range(K*K):
        ans1 += P[i][j] * B[j] % mod
        ans1 %= mod

ans2 = ans1 * N * (K - 1) * pow(2, mod-2, mod) % mod
print(ans1, ans2)
0