結果

問題 No.1621 Sequence Inversions
ユーザー shotoyooshotoyoo
提出日時 2021-07-22 22:20:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 468 ms / 3,000 ms
コード長 1,309 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 96,372 KB
最終ジャッジ日時 2023-09-24 17:29:57
合計ジャッジ時間 8,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,224 KB
testcase_01 AC 95 ms
71,600 KB
testcase_02 AC 110 ms
77,164 KB
testcase_03 AC 98 ms
71,216 KB
testcase_04 AC 97 ms
71,468 KB
testcase_05 AC 100 ms
71,436 KB
testcase_06 AC 105 ms
77,572 KB
testcase_07 AC 116 ms
77,464 KB
testcase_08 AC 394 ms
84,388 KB
testcase_09 AC 465 ms
96,372 KB
testcase_10 AC 468 ms
96,104 KB
testcase_11 AC 388 ms
84,504 KB
testcase_12 AC 357 ms
78,856 KB
testcase_13 AC 342 ms
77,840 KB
testcase_14 AC 459 ms
78,156 KB
testcase_15 AC 316 ms
77,632 KB
testcase_16 AC 262 ms
77,772 KB
testcase_17 AC 308 ms
77,604 KB
testcase_18 AC 264 ms
77,776 KB
testcase_19 AC 124 ms
77,400 KB
testcase_20 AC 172 ms
77,732 KB
testcase_21 AC 323 ms
77,856 KB
testcase_22 AC 315 ms
77,800 KB
testcase_23 AC 316 ms
77,744 KB
testcase_24 AC 96 ms
71,568 KB
testcase_25 AC 94 ms
71,468 KB
testcase_26 AC 99 ms
71,724 KB
testcase_27 AC 96 ms
71,648 KB
testcase_28 AC 91 ms
71,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

def merge(a,b):
    n = len(a)
    m = len(b)
    c = [0]*(n+m-1)
    for i in range(n):
        for j in range(m):
            c[i+j] += a[i]*b[j]%M
            if c[i+j] > M:
                c[i+j] -= M
    return c
def sub(v,k):
    kk = min(v*k, K)
    res = [[0]*(kk+1) for _ in range(k+1)]
    res[0][0] = 1
    for i in range(v+1):
        nres = [[0]*(kk+1) for _ in range(k+1)]
        for j in range(k+1):
            for l in range(kk+1):
                val = res[j][l]
                if val==0:
                    continue
                for jj in range((k-j)+1):
                    nl = l+jj*(v-i)
                    if nl<=kk:
                        nres[j+jj][nl] += val
                        nres[j+jj][nl] %= M
        res = nres
    return res[k]
n,K = list(map(int, input().split()))
a = list(map(int, input().split()))
M = 998244353
from collections import Counter
c = Counter(a)
kvs = sorted(c.items())
num = 0
dp = [1]
for k,v in kvs:
    t = sub(num, v)
    dp = merge(dp, t)
    num += v
if len(dp)<K+1:
    ans = 0
else:
    ans = dp[K]
print(ans%M)
0