結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー 👑 rin204rin204
提出日時 2022-01-28 20:57:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,617 ms / 6,000 ms
コード長 2,257 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 102,212 KB
最終ジャッジ日時 2023-08-28 18:28:40
合計ジャッジ時間 15,423 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,660 KB
testcase_01 AC 209 ms
78,100 KB
testcase_02 AC 1,381 ms
90,492 KB
testcase_03 AC 107 ms
77,956 KB
testcase_04 AC 107 ms
77,828 KB
testcase_05 AC 107 ms
77,640 KB
testcase_06 AC 143 ms
77,992 KB
testcase_07 AC 209 ms
78,376 KB
testcase_08 AC 328 ms
79,804 KB
testcase_09 AC 90 ms
76,668 KB
testcase_10 AC 124 ms
77,644 KB
testcase_11 AC 97 ms
77,288 KB
testcase_12 AC 100 ms
77,572 KB
testcase_13 AC 94 ms
76,968 KB
testcase_14 AC 2,500 ms
102,212 KB
testcase_15 AC 1,148 ms
88,852 KB
testcase_16 AC 557 ms
81,000 KB
testcase_17 AC 264 ms
79,172 KB
testcase_18 AC 156 ms
78,240 KB
testcase_19 AC 129 ms
77,972 KB
testcase_20 AC 2,617 ms
101,432 KB
testcase_21 AC 2,549 ms
101,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
MOD = 998244353

n, k = map(int, input().split())
k2 = 2 * k * k
A = [[0] * k2 for _ in range(k2)]
B = [0] * k2
f = lambda x, y: x * k + y

for i in range(k):
    for j in range(i + 1, k):
        p = 2 * f(i, j)
        B[p] += 1
        B[p + 1] += i + j
        for i2 in range(j):
            if i2 == i:
                continue
            for j2 in range(i2 + 1, k):
                if j2 == j:
                    continue
                p2 = 2 * f(i2, j2)
                A[p2][p] += 1
                A[p2 + 1][p] += i2 + j2
                A[p2 + 1][p + 1] += 1

for i in range(k):
    for j in range(i):
        p = 2 * f(i, j)
        B[p] += 1
        B[p + 1] += i + j
        for i2 in range(j + 1, k):
            if i2 == i:
                continue
            for j2 in range(i2):
                if j2 == j:
                    continue
                p2 = 2 * f(i2, j2)
                A[p2][p] += 1
                A[p2 + 1][p] += i2 + j2
                A[p2 + 1][p + 1] += 1
                
                
A[-1][-1] = 1
t = n // 2 - 1

while t:
    if t & 1:
        C = [0] * k2
        for i in range(k2):
            for j in range(k2):
                C[i] += A[i][j] * B[j]
            C[i] %= MOD
        B = C.copy()
    t >>= 1
    C = [[0] * k2 for _ in range(k2)]
    for i in range(k2):
        for j in range(k2):
            for l in range(k2):
                C[i][j] += A[i][l] * A[l][j]
            C[i][j] %= MOD
    A = deepcopy(C)

if n % 2 == 0:
    cnt = 0
    tot = 0
    for i, b in enumerate(B):
        if i % 2 == 0:
            cnt += b
            cnt %= MOD
        else:
            tot += b
            tot %= MOD
    print(cnt, tot)
    
else:
    cnt = 0
    tot = 0
    for i in range(k):
        for j in range(k):
            p = 2 * f(i, j)
            if i < j:
                for l in range(j):
                    if i != l:
                        cnt += B[p]
                        tot += B[p] * l + B[p + 1]
            else:
                for l in range(j + 1, k):
                    if i != l:
                        cnt += B[p]
                        tot += B[p] * l + B[p + 1]
            cnt %= MOD
            tot %= MOD
    print(cnt, tot)
    
0