結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2020-11-02 23:36:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 5,000 ms |
| コード長 | 1,081 bytes |
| コンパイル時間 | 830 ms |
| コンパイル使用メモリ | 75,616 KB |
| 実行使用メモリ | 10,240 KB |
| 最終ジャッジ日時 | 2025-01-03 01:59:54 |
| 合計ジャッジ時間 | 2,391 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
int n, d, k;
cin >> n >> d >> k;
vector<vector<vector<bool>>> dp(n + 1, vector<vector<bool>>(d + 1, vector<bool>(k + 1)));
dp[n][d][k] = true;
for (int i = n; i >= 0; i--) {
for (int j = d; j >= 0; j--) {
for (int l = k; l >= 0; l--) {
if (i > 0 && dp[i][j][l]) {
dp[i - 1][j][l] = true;
}
if (i > 0 && j >= i && l > 0 && dp[i][j][l]) {
dp[i - 1][j - i][l - 1] = true;
}
}
}
}
if (!dp[0][0][0]) {
cout << -1 << endl;
return 0;
}
bool first = true;
int cost = 0, count = 0;
for (int i = 0; i < n; i++) {
if (dp[i + 1][cost + i + 1][count + 1]) {
if (!first)cout << " ";
first = false;
cout << i + 1;
cost += i + 1, count++;
}
if (cost == d)break;
}
cout << endl;
return 0;
}
mencotton