結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2020-09-08 18:36:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 833 bytes |
| コンパイル時間 | 1,114 ms |
| コンパイル使用メモリ | 83,316 KB |
| 最終ジャッジ日時 | 2025-01-14 08:35:17 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main(){
int N, D, K;
cin >> N >> D >> K;
vector<vector<vector<bool>>> dp(N + 1, vector<vector<bool>>(K + 1, vector<bool>(D + 1, false)));
dp[0][0][0] = true;
for (int i = 0; i < N; i++){
dp[i + 1] = dp[i];
for (int j = 0; j < K; j++){
for (int k = 0; k < D; k++){
if (dp[i][j][k] && k + N - i <= D){
dp[i + 1][j + 1][k + N - i] = true;
}
}
}
}
if (!dp[N][K][D]){
cout << -1 << endl;
} else {
vector<int> ans;
int cnt = K;
int total = D;
for (int i = N - 1; i >= 0; i--){
int c = N - i;
if (total >= c){
if (dp[i][cnt - 1][total - c]){
ans.push_back(c);
cnt--;
total -= c;
}
}
}
for (int i = 0; i < K; i++){
cout << ans[i];
if (i < K - 1){
cout << ' ';
}
}
cout << endl;
}
}
SSRS