結果

問題 No.115 遠足のおやつ
ユーザー furafura
提出日時 2020-04-17 03:37:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 934 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 200,744 KB
実行使用メモリ 7,892 KB
最終ジャッジ日時 2023-08-31 00:58:15
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
6,764 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
5,588 KB
testcase_09 AC 2 ms
5,040 KB
testcase_10 AC 3 ms
5,940 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
5,992 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
6,232 KB
testcase_16 AC 3 ms
6,460 KB
testcase_17 AC 2 ms
6,204 KB
testcase_18 AC 2 ms
5,728 KB
testcase_19 AC 2 ms
5,856 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
6,216 KB
testcase_22 AC 3 ms
5,880 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
6,248 KB
testcase_25 AC 2 ms
6,276 KB
testcase_26 AC 2 ms
5,892 KB
testcase_27 AC 2 ms
5,764 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
6,204 KB
testcase_30 AC 3 ms
6,340 KB
testcase_31 AC 3 ms
6,084 KB
testcase_32 AC 3 ms
6,500 KB
testcase_33 AC 2 ms
5,932 KB
testcase_34 AC 3 ms
6,416 KB
testcase_35 AC 2 ms
6,072 KB
testcase_36 AC 3 ms
6,108 KB
testcase_37 AC 3 ms
6,476 KB
testcase_38 AC 6 ms
7,828 KB
testcase_39 AC 6 ms
7,892 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n,d,k; scanf("%d%d%d",&n,&d,&k);

	// dp[i][w][j] = i+1 円以上の商品だけからちょうど d 個選んで w 円を作るときの, 選べる商品の値段の最小値 (作れないなら INF)
	int dp[101][1001][11];
	rep(i,n+1) rep(w,d+1) rep(j,k+1) dp[i][w][j]=INF;
	rep(i,n+1) dp[i][0][0]=n+1;
	for(int i=n;i>0;i--){
		for(int w=d-i;w>=0;w--){
			for(int j=k-1;j>=0;j--){
				dp[i-1][w+i][j+1]=dp[i][w+i][j+1];
				if(dp[i][w][j]<INF){
					dp[i-1][w+i][j+1]=min(dp[i-1][w+i][j+1],i);
				}
			}
		}
	}

	int i;
	for(i=0;i<n;i++) if(dp[i][d][k]<INF) break;
	if(i==n) return puts("-1"),0;

	vector<int> ans;
	int w=d,j=k;
	while(w>0){
		int next=dp[i][w][j];
		ans.emplace_back(next);
		w-=next;
		j--;
		i=next;
	}
	rep(i,ans.size()) printf("%d%c",ans[i],i+1<ans.size()?' ':'\n');

	return 0;
}
0