結果

問題 No.1621 Sequence Inversions
ユーザー mkawa2mkawa2
提出日時 2021-07-22 22:55:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,332 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 12,392 KB
最終ジャッジ日時 2023-09-24 18:38:32
合計ジャッジ時間 7,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,728 KB
testcase_01 AC 21 ms
8,724 KB
testcase_02 AC 57 ms
9,032 KB
testcase_03 AC 22 ms
8,816 KB
testcase_04 AC 24 ms
9,188 KB
testcase_05 AC 21 ms
8,876 KB
testcase_06 AC 25 ms
9,116 KB
testcase_07 AC 97 ms
12,392 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)
        res %= md
    return res

from collections import Counter

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

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