結果

問題 No.1621 Sequence Inversions
ユーザー mkawa2mkawa2
提出日時 2021-07-22 22:49:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 91,204 KB
最終ジャッジ日時 2023-09-24 18:26:59
合計ジャッジ時間 5,818 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,696 KB
testcase_01 AC 21 ms
8,764 KB
testcase_02 AC 60 ms
9,116 KB
testcase_03 AC 22 ms
9,032 KB
testcase_04 AC 30 ms
10,456 KB
testcase_05 AC 21 ms
8,688 KB
testcase_06 AC 25 ms
9,000 KB
testcase_07 AC 89 ms
12,572 KB
testcase_08 TLE -
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

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

from functools import lru_cache

@lru_cache(None)
def divide(s, n, lim):
    if s > lim*n: return 0
    if n == 1: return 1
    res = 0
    for a in range(lim+1):
        if a*n > s: break
        res += divide(s-a*n, n-1, lim-a)
    return res

def RLE(s):
    kk = []
    vv = []
    for c in s:
        if kk and kk[-1] == c:
            vv[-1] += 1
        else:
            kk.append(c)
            vv.append(1)
    return kk, vv

from collections import Counter

n, k = LI()
aa = LI()
aa.sort()
ac = Counter(aa)
dp = [[0]*(k+1) for _ in range(n+1)]
dp[0][0] = 1

pa = -1
for i, a in enumerate(aa):
    if a == pa: continue
    c = ac[a]
    for j in range(k+1):
        pre = dp[i][j]
        if pre == 0: continue
        for nj in range(j, k+1):
            diff = nj-j
            dp[i+c][nj] = (dp[i+c][nj]+pre*divide(diff, c, i))%md
    pa = a
# p2D(dp)
print(dp[n][k])
0