結果

問題 No.1621 Sequence Inversions
ユーザー だれだれ
提出日時 2021-07-06 19:47:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,541 ms / 3,000 ms
コード長 1,203 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 307,508 KB
最終ジャッジ日時 2023-09-24 15:04:55
合計ジャッジ時間 28,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 371 ms
298,824 KB
testcase_01 AC 335 ms
298,408 KB
testcase_02 AC 357 ms
299,948 KB
testcase_03 AC 343 ms
298,244 KB
testcase_04 AC 347 ms
298,260 KB
testcase_05 AC 331 ms
298,372 KB
testcase_06 AC 373 ms
299,824 KB
testcase_07 AC 510 ms
300,068 KB
testcase_08 AC 2,216 ms
303,032 KB
testcase_09 AC 2,277 ms
307,508 KB
testcase_10 AC 2,256 ms
307,408 KB
testcase_11 AC 2,262 ms
303,328 KB
testcase_12 AC 2,541 ms
300,596 KB
testcase_13 AC 867 ms
300,708 KB
testcase_14 AC 900 ms
301,668 KB
testcase_15 AC 834 ms
303,012 KB
testcase_16 AC 751 ms
303,060 KB
testcase_17 AC 854 ms
303,236 KB
testcase_18 AC 737 ms
303,060 KB
testcase_19 AC 383 ms
299,980 KB
testcase_20 AC 545 ms
301,844 KB
testcase_21 AC 835 ms
303,320 KB
testcase_22 AC 833 ms
303,316 KB
testcase_23 AC 845 ms
303,228 KB
testcase_24 AC 346 ms
299,284 KB
testcase_25 AC 339 ms
299,184 KB
testcase_26 AC 323 ms
298,428 KB
testcase_27 AC 335 ms
298,796 KB
testcase_28 AC 336 ms
298,916 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()

a.sort()
cnt = [0] * 100
n = 0
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

cursum = 0

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

print(dp[n][k])
0