結果

問題 No.1621 Sequence Inversions
ユーザー neterukunneterukun
提出日時 2021-07-22 23:18:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,401 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 92,456 KB
最終ジャッジ日時 2023-09-24 19:28:28
合計ジャッジ時間 11,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
78,580 KB
testcase_01 AC 70 ms
71,436 KB
testcase_02 AC 94 ms
76,784 KB
testcase_03 AC 86 ms
76,584 KB
testcase_04 AC 274 ms
77,164 KB
testcase_05 AC 66 ms
71,344 KB
testcase_06 AC 92 ms
77,276 KB
testcase_07 AC 130 ms
77,756 KB
testcase_08 AC 1,452 ms
85,496 KB
testcase_09 TLE -
testcase_10 TLE -
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 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


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):
                if use + used >= cnt + 1:
                    break
                for val in range(k + 1):
                    if val + i * use < k + 1:
                        tmp[val + i * use][used + use] += coeff[val][used]
                        tmp[val + i * use][used + use] %= MOD
                    else:
                        break
        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