結果

問題 No.615 集合に分けよう
ユーザー kk
提出日時 2020-07-28 02:52:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 740 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 202,064 KB
実行使用メモリ 4,440 KB
最終ジャッジ日時 2023-09-11 06:18:00
合計ジャッジ時間 6,959 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,440 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 TLE -
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 #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long INF = 1LL<<60;
int n, k;
long long a[55555];
long long dp[2][55555];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> k;
  REP (i, n) cin >> a[i];
  sort(a, a + n);

  REP (i, 2) REP (j, 55555) dp[i][j] = INF;
  dp[0][0] = 0;

  REP (i, n) {
    int cur = i & 1;
    int nxt = (i + 1) & 1;
    fill(dp[nxt], dp[nxt]+k+1, INF);
    REP (j, k+1) {
      if (dp[cur][j] == INF) continue;
      if (i >= 1)
        dp[nxt][j] = min(dp[nxt][j], dp[cur][j] - a[i-1] + a[i]);
      if (j + 1 <= k)
        dp[nxt][j+1] = min(dp[nxt][j+1] , dp[cur][j]);
    }
  }

  cout << dp[n&1][k] << endl;

  return 0;
}
0