結果

問題 No.115 遠足のおやつ
ユーザー kimiyuki
提出日時 2017-01-02 18:29:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,202 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-03 01:18:18
合計ジャッジ時間 2,346 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
const vector<int> inf { int(1e9+7) };
int main() {
    int n, d, k; cin >> n >> d >> k;
    auto dp = vectors(d+1, k+1, inf);
    dp[0][0] = {};
    repeat_from (a,1,n+1) {
        repeat_reverse (i,d) if (i+a < d+1) {
            repeat (j,k) {
                vector<int> it = dp[i][j];
                it.push_back(a);
                setmin(dp[i+a][j+1], it);
            }
        }
    }
    if (dp[d][k] == inf) {
        cout << -1 << endl;
    } else {
        repeat (i, dp[d][k].size()) {
            if (i) cout << ' ';
            cout << dp[d][k][i];
        }
        cout << endl;
    }
    return 0;
}
0