結果

問題 No.115 遠足のおやつ
ユーザー llllll
提出日時 2018-04-09 22:16:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,733 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 96,700 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 03:36:39
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

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

    int N, D, K;
    cin >> N >> D >> K;

    // dp[i][j] := i個選んだとき合計がj円
    // dp[i+1][j] := dp[i][j-n]

    vector<int> dp[12][1010];
    for (int i = 0; i < 12; i++) {
        for (int j = 0; j < 1010; j++) {
            dp[i][j] = {};
        }
    }

    dp[0][0] = {0};

    for (int n = 1; n <= N; n++) {
        for (int i = 0; i < K; i++) {
            for (int j = 0; j <= D; j++) {
                if (j - n >= 0 && dp[i][j - n].size() != 0 &&
                    (find(dp[i][j - n].begin(), dp[i][j - n].end(), n) ==
                        dp[i][j - n].end())) {
                    if (dp[i + 1][j].size() == 0) {
                        copy(dp[i][j - n].begin(), dp[i][j - n].end(),
                            back_inserter(dp[i + 1][j]));
                        dp[i + 1][j].push_back(n);
                    } else {
                        dp[i + 1][j] = {};
                        copy(dp[i][j - n].begin(), dp[i][j - n].end(),
                            back_inserter(dp[i + 1][j]));
                        dp[i + 1][j].push_back(n);
                    }
                }
            }
        }
    }

    if (dp[K][D].size() != 0) {
        for (int i = 1; i <= K; i++) {
            if (i > 1)
                cout << " ";
            cout << dp[K][D][i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}
0