結果

問題 No.115 遠足のおやつ
ユーザー lapilapi
提出日時 2019-03-28 13:53:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 1,375 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 106,848 KB
実行使用メモリ 67,736 KB
最終ジャッジ日時 2023-08-31 00:50:59
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
29,428 KB
testcase_01 AC 19 ms
30,856 KB
testcase_02 AC 15 ms
30,060 KB
testcase_03 AC 13 ms
29,688 KB
testcase_04 AC 71 ms
43,508 KB
testcase_05 AC 12 ms
29,444 KB
testcase_06 AC 13 ms
29,532 KB
testcase_07 AC 13 ms
29,636 KB
testcase_08 AC 16 ms
30,520 KB
testcase_09 AC 20 ms
31,520 KB
testcase_10 AC 20 ms
31,768 KB
testcase_11 AC 13 ms
29,840 KB
testcase_12 AC 15 ms
30,280 KB
testcase_13 AC 13 ms
29,456 KB
testcase_14 AC 16 ms
30,056 KB
testcase_15 AC 48 ms
37,636 KB
testcase_16 AC 63 ms
41,452 KB
testcase_17 AC 29 ms
33,336 KB
testcase_18 AC 13 ms
29,532 KB
testcase_19 AC 16 ms
30,304 KB
testcase_20 AC 16 ms
30,220 KB
testcase_21 AC 15 ms
29,912 KB
testcase_22 AC 37 ms
35,240 KB
testcase_23 AC 18 ms
30,612 KB
testcase_24 AC 36 ms
34,888 KB
testcase_25 AC 28 ms
33,620 KB
testcase_26 AC 17 ms
30,644 KB
testcase_27 AC 21 ms
31,552 KB
testcase_28 AC 18 ms
30,704 KB
testcase_29 AC 21 ms
31,504 KB
testcase_30 AC 35 ms
34,724 KB
testcase_31 AC 20 ms
31,340 KB
testcase_32 AC 52 ms
38,776 KB
testcase_33 AC 15 ms
30,048 KB
testcase_34 AC 71 ms
43,308 KB
testcase_35 AC 27 ms
32,796 KB
testcase_36 AC 34 ms
34,456 KB
testcase_37 AC 54 ms
38,792 KB
testcase_38 AC 165 ms
65,960 KB
testcase_39 AC 171 ms
67,736 KB
testcase_40 AC 13 ms
29,496 KB
testcase_41 AC 13 ms
29,424 KB
testcase_42 AC 13 ms
29,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

vector<int> dp[101][11][1001]; // dp[i][j][k] : 1~i番目のお菓子の中から,j個選んで合計がkになるときの最小順列
							   // 1 <= i <= N
							   // 1 <= j <= K
							   // 1 <= k <= D

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

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

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k <= D; k++) dp[i][j][k].push_back(INF);
		}
	}

	dp[0][0][0].clear(); dp[0][0][0].push_back(0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k <= D; k++) {
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				if (k + i + 1 <= D && j < K) {
					vector<int> tmp = dp[i][j][k];
					tmp.push_back(i + 1);
					dp[i + 1][j + 1][k + i + 1] = min(dp[i + 1][j + 1][k + i + 1], tmp);
				}
			}
		}
	}

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

	return 0;
}
0