結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-24 22:07:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 427 ms / 6,000 ms
コード長 1,169 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 77,360 KB
最終ジャッジ日時 2023-08-03 08:54:15
合計ジャッジ時間 7,304 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,704 KB
testcase_01 AC 109 ms
76,324 KB
testcase_02 AC 235 ms
77,360 KB
testcase_03 AC 81 ms
76,440 KB
testcase_04 AC 83 ms
76,384 KB
testcase_05 AC 84 ms
76,252 KB
testcase_06 AC 90 ms
76,544 KB
testcase_07 AC 108 ms
76,492 KB
testcase_08 AC 118 ms
76,520 KB
testcase_09 AC 79 ms
75,912 KB
testcase_10 AC 91 ms
76,436 KB
testcase_11 AC 80 ms
76,304 KB
testcase_12 AC 84 ms
76,248 KB
testcase_13 AC 81 ms
76,388 KB
testcase_14 AC 381 ms
77,260 KB
testcase_15 AC 224 ms
77,204 KB
testcase_16 AC 153 ms
76,908 KB
testcase_17 AC 111 ms
76,504 KB
testcase_18 AC 88 ms
76,380 KB
testcase_19 AC 88 ms
76,172 KB
testcase_20 AC 427 ms
77,244 KB
testcase_21 AC 422 ms
77,176 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