結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー ayaoniayaoni
提出日時 2021-05-22 06:50:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 6,000 ms
コード長 1,668 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 79,800 KB
最終ジャッジ日時 2024-04-18 17:27:48
合計ジャッジ時間 6,056 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,092 KB
testcase_01 AC 126 ms
76,248 KB
testcase_02 AC 443 ms
77,844 KB
testcase_03 AC 49 ms
63,380 KB
testcase_04 AC 46 ms
62,276 KB
testcase_05 AC 57 ms
72,328 KB
testcase_06 AC 85 ms
76,720 KB
testcase_07 AC 124 ms
76,640 KB
testcase_08 AC 156 ms
76,204 KB
testcase_09 AC 45 ms
59,764 KB
testcase_10 AC 79 ms
76,676 KB
testcase_11 AC 56 ms
69,360 KB
testcase_12 AC 51 ms
64,804 KB
testcase_13 AC 47 ms
61,812 KB
testcase_14 AC 820 ms
79,068 KB
testcase_15 AC 421 ms
77,768 KB
testcase_16 AC 241 ms
77,120 KB
testcase_17 AC 138 ms
76,548 KB
testcase_18 AC 79 ms
75,980 KB
testcase_19 AC 72 ms
76,076 KB
testcase_20 AC 938 ms
79,796 KB
testcase_21 AC 932 ms
79,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


def matrix_multiplication_mod(A,B,p):
    l = len(A)
    m = len(B)
    n = len(B[0])
    C = [[0]*n for _ in range(l)]
    for i in range(l):
        for j in range(n):
            C[i][j] = sum((A[i][k]*B[k][j]) % p for k in range(m)) % p
    return C


def matrix_power_mod(A,n,p):
    l = len(A)
    C = [[0] * l for _ in range(l)]
    for i in range(l):
        C[i][i] = 1
    while n > 0:
        if n % 2 == 1:
            C = matrix_multiplication_mod(C,A,p)
        A = matrix_multiplication_mod(A,A,p)
        n >>= 1
    return C


N,K = MI()
mod = 998244353

A = [[0]*(K**2) for _ in range(K**2)]
for j in range(K):
    for k in range(K):
        i = K*j+k
        if j < k:
            for l in range(k):
                if l == j:
                    continue
                A[i][K*k+l] = 1
        else:
            for l in range(k+1,K):
                if l == j:
                    continue
                A[i][K*k+l] = 1

X = matrix_power_mod(A,N-2,mod)
ans1 = 0
for i in range(K):
    for j in range(K):
        if i == j:
            continue
        for k in range(K**2):
            ans1 += X[K*i+j][k]
            ans1 %= mod

ans2 = ans1*N*(K-1)*(mod+1)//2
ans2 %= mod

print(ans1,ans2)
0