結果
| 問題 | No.1621 Sequence Inversions | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-07-22 22:20:27 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 429 ms / 3,000 ms | 
| コード長 | 1,309 bytes | 
| コンパイル時間 | 525 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 96,220 KB | 
| 最終ジャッジ日時 | 2024-07-17 18:22:19 | 
| 合計ジャッジ時間 | 6,699 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 | 
ソースコード
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)
            
            
            
        