結果
| 問題 | No.615 集合に分けよう |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-02 23:35:58 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,093 bytes |
| 記録 | |
| コンパイル時間 | 457 ms |
| コンパイル使用メモリ | 93,880 KB |
| 実行使用メモリ | 11,996 KB |
| 最終ジャッジ日時 | 2026-07-04 16:18:16 |
| 合計ジャッジ時間 | 7,407 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 9 WA * 3 RE * 1 TLE * 1 -- * 12 |
ソースコード
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
const int INF = INT_MAX / 2;
int main() {
int n, k;
cin >> n >> k;
int A[n];
for(int i = 0; i < n; i++) cin >> A[i];
sort(A, A + n);
// DP[i][j] represents the minimum sum of sizes of sets obtained by dividing the first i elements into j subsets.
int DP[n + 1][k + 1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= k; j++) {
DP[i][j] = INF;
}
}
// Base case: If we have 0 elements, the minimum sum is 0 for any number of subsets.
for(int j = 0; j <= k; j++) {
DP[0][j] = 0;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= k; j++) {
for(int p = 0; p < i; p++) {
// Calculate the size of the current subset.
int size = A[i - 1] - A[p];
// Update the DP table.
DP[i][j] = min(DP[i][j], DP[p][j - 1] + size);
}
}
}
// The answer will be stored in DP[n][k].
cout << DP[n][k] << endl;
return 0;
}