結果

問題 No.1621 Sequence Inversions
ユーザー だれだれ
提出日時 2021-07-06 07:49:21
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,191 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 307,736 KB
最終ジャッジ日時 2023-09-24 15:02:32
合計ジャッジ時間 32,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 377 ms
299,088 KB
testcase_01 AC 363 ms
298,304 KB
testcase_02 AC 402 ms
300,048 KB
testcase_03 AC 365 ms
298,376 KB
testcase_04 AC 365 ms
298,528 KB
testcase_05 AC 364 ms
298,308 KB
testcase_06 AC 412 ms
299,948 KB
testcase_07 AC 604 ms
300,152 KB
testcase_08 AC 2,947 ms
303,420 KB
testcase_09 AC 2,838 ms
307,548 KB
testcase_10 AC 2,937 ms
307,736 KB
testcase_11 AC 2,856 ms
303,444 KB
testcase_12 TLE -
testcase_13 AC 905 ms
300,580 KB
testcase_14 AC 927 ms
301,732 KB
testcase_15 AC 873 ms
303,256 KB
testcase_16 AC 775 ms
303,216 KB
testcase_17 AC 862 ms
303,316 KB
testcase_18 AC 760 ms
303,004 KB
testcase_19 AC 403 ms
300,044 KB
testcase_20 AC 569 ms
301,744 KB
testcase_21 AC 865 ms
303,360 KB
testcase_22 AC 876 ms
303,496 KB
testcase_23 AC 869 ms
303,092 KB
testcase_24 AC 385 ms
299,080 KB
testcase_25 AC 383 ms
299,476 KB
testcase_26 AC 365 ms
298,276 KB
testcase_27 AC 382 ms
299,040 KB
testcase_28 AC 378 ms
298,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

memo = [[[-1] * 101 for _ in range(2501)] for _ in range(101)]

def f(n, m, k) -> int:
    if memo[n][m][k] != -1:
        return memo[n][m][k]
    if n == 0:
        if m == 0:
            memo[n][m][k] = 1
            return 1
        else:
            memo[n][m][k] = 0
            return 0
    if n * k < m:
        memo[n][m][k] = 0
        return 0
    memo[n][m][k] = f(n - 1, m, k)
    if m - n >= 0 and k > 0:
        memo[n][m][k] += f(n, m - n, k - 1)
        if memo[n][m][k] >= mod:
            memo[n][m][k] -= mod
    return memo[n][m][k]

t, k = map(int, input().split())
a = list(map(int, input().split()))
if k > t * (t - 1) // 2:
    print(0)
    exit()
n = 0
a.sort()
cnt = [0] * 100
for i in range(t-1):
    cnt[n] += 1
    if a[i] != a[i + 1]:
        n += 1

cnt[n] += 1
n += 1

dp = [[0] * 5000 for _ in range(n + 1)]
dp[0][0] = 1

rui = 0

for i in range(1, n + 1):
    x = cnt[i - 1]
    for j in range(5000):
        for l in range(rui * x + 1):
            if j - l < 0:
                break
            dp[i][j] += f(x, l, rui) * dp[i - 1][j - l]
            if dp[i][j] >= mod:    
                dp[i][j] %= mod
    rui += x

print(dp[n][k])
0