結果

問題 No.1621 Sequence Inversions
ユーザー neterukunneterukun
提出日時 2021-07-22 23:16:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,872 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 94,792 KB
最終ジャッジ日時 2023-09-24 19:22:39
合計ジャッジ時間 10,397 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
76,320 KB
testcase_01 AC 99 ms
76,360 KB
testcase_02 AC 138 ms
77,892 KB
testcase_03 AC 118 ms
77,580 KB
testcase_04 AC 325 ms
80,396 KB
testcase_05 AC 95 ms
76,332 KB
testcase_06 AC 126 ms
77,552 KB
testcase_07 AC 178 ms
78,276 KB
testcase_08 AC 2,798 ms
94,792 KB
testcase_09 TLE -
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 #

def way10(ball, box):
    """ball: False / box: False / constraints: None
    ans = P(ball, box) Pは分割数 / 計算量 O(ball * box)
    """
    # P[i][j] := 整数iを順序を区別せずに「j以下の自然数」の和に分ける場合の数
    P = [[0] * (ball + 1) for _ in range(ball + 1)]
    for j in range(ball + 1):
        P[0][j] = 1
    for i in range(ball):
        for j in range(ball):
            if i - j >= 0:
                P[i + 1][j + 1] = (P[i + 1][j] + P[i - j][j + 1]) % MOD
            else:
                P[i + 1][j + 1] = P[i + 1][j]
    return P[ball][min(box, ball)]


def encoding(s):
    n = len(s)
    begin, cnt = 0, 0
    ans = []
    if n == 0:
        return ans
    for end in range(n + 1):
        if end == n or s[begin] != s[end]:
            ans.append((s[begin], cnt))
            begin, cnt = end, 1
        else:
            cnt += 1
    return ans


n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
P = way10(1000, 1000)


a = sorted(a)
comp = encoding(a)
cnts = [cnt for _, cnt in comp]


dp = [0] * (k + 1)
dp[0] = 1
ru_cnt = 0

for cnt in cnts:
    dq = [0] * (k + 1)
    
    coeff = [[0] * (cnt + 1) for _ in range(k + 1)]
    coeff[0][0] = 1

    for i in range(ru_cnt + 1):
        tmp = [[0] * (cnt + 1) for _ in range(k + 1)]
        for use in range(cnt + 1):
            for used in range(cnt + 1):
                for val in range(k + 1):
                    if use + used < cnt + 1 and val + i * use < k + 1:
                        tmp[val + i * use][used + use] += coeff[val][used]
        coeff, tmp = tmp, coeff

    for count in range(k + 1):
        for j in range(k + 1):
            if count + j < k + 1:
                dq[count + j] += dp[count] * coeff[j][-1]
                dq[count + j] %= MOD
    ru_cnt += cnt
    dp, dq = dq, dp

print(dp[-1] % MOD)
0