結果

問題 No.1621 Sequence Inversions
ユーザー ayaoniayaoni
提出日時 2021-07-22 23:13:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,346 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 81,236 KB
最終ジャッジ日時 2023-09-24 19:15:11
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
76,276 KB
testcase_01 AC 89 ms
71,432 KB
testcase_02 AC 123 ms
77,996 KB
testcase_03 AC 186 ms
81,236 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
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())


N,K = MI()
A = LI()
mod = 998244353

count = defaultdict(int)
for a in A:
    count[a] += 1
B = list(count.keys())
M = len(B)
B.sort()

X = [[[0]*(K+1) for _ in range(N+1)] for _ in range(N+1)]
X[0][0][0] = 1
for i in range(1,N+1):
    for j in range(N+1):
        for k in range(K+1):
            for l in range(j+1):
                if (i-1)*l > k:
                    break
                X[i][j][k] += X[i-1][j-l][k-(i-1)*l]
                X[i][j][k] %= mod

dp = [[0]*(K+1) for _ in range(M+1)]
dp[1][0] = 1
s = count[B[0]]
for i in range(1,M):
    c = count[B[i]]
    XX = X[s+1][c]
    for j in range(K+1):
        d = dp[i][j]
        if not d:
            continue
        for k in range(K+1):
            if j+k > K:
                break
            dp[i+1][j+k] += d*XX[k]
            dp[i+1][j+k] %= mod
    s += c

ans = dp[-1][-1]
print(ans)
0