結果

問題 No.615 集合に分けよう
ユーザー ThetaTheta
提出日時 2022-10-21 11:23:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 705 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 602,348 KB
最終ジャッジ日時 2023-09-13 13:28:41
合計ジャッジ時間 5,910 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,412 KB
testcase_01 AC 16 ms
8,352 KB
testcase_02 AC 16 ms
8,240 KB
testcase_03 AC 17 ms
8,256 KB
testcase_04 AC 17 ms
8,360 KB
testcase_05 AC 17 ms
8,192 KB
testcase_06 AC 17 ms
8,384 KB
testcase_07 AC 17 ms
8,332 KB
testcase_08 AC 18 ms
8,288 KB
testcase_09 AC 17 ms
8,412 KB
testcase_10 AC 18 ms
8,248 KB
testcase_11 AC 18 ms
8,332 KB
testcase_12 AC 21 ms
8,460 KB
testcase_13 AC 19 ms
8,632 KB
testcase_14 AC 31 ms
9,852 KB
testcase_15 AC 34 ms
10,560 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import pairwise
from math import inf


def main():
    N, K = map(int, input().split())
    a = sorted(map(int, input().split()))

    a_diff = [0]
    for a_elm1, a_elm2 in pairwise(a):
        a_diff.append(a_elm2 - a_elm1)
    dp_table = [[0 for _ in range(K+1)] for _ in range(N+1)]

    dp_table[0][0] = 0
    for idx in range(1, N+1):
        dp_table[idx][0] = inf

    for idx in range(1, K+1):
        dp_table[0][idx] = inf

    for k in range(1, K+1):
        for n in range(1, N+1):
            dp_table[n][k] = min(
                dp_table[n-1][k-1],
                dp_table[n-1][k]+a_diff[n-1]
            )
    print(dp_table[N][K])


if __name__ == "__main__":
    main()
0