結果

問題 No.1621 Sequence Inversions
コンテスト
ユーザー shotoyoo
提出日時 2021-07-22 22:20:27
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 273 ms / 3,000 ms
コード長 1,309 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 184 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 97,152 KB
最終ジャッジ日時 2026-04-01 08:44:04
合計ジャッジ時間 4,476 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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