結果

問題 No.115 遠足のおやつ
ユーザー SSRSSSRS
提出日時 2020-09-08 18:35:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 1,828 ms
コンパイル使用メモリ 88,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 10:59:31
合計ジャッジ時間 2,536 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N, D, K;
	cin >> N >> D >> K;
	vector<vector<vector<bool>>> dp(N + 1, vector<vector<bool>>(K + 1, vector<bool>(D + 1, false)));
	dp[0][0][0] = true;
	for (int i = 0; i < N; i++){
		dp[i + 1] = dp[i];
		for (int j = 0; j < K; j++){
			for (int k = 0; k < D; k++){
				if (dp[i][j][k] && k + N - i <= D){
					dp[i + 1][j + 1][k + N - i] = true;
				}
			}
		}
	}
	if (!dp[N][K][D]){
		cout << -1 << endl;
	} else {
		vector<int> ans;
		int cnt = K;
		int total = D;
		for (int i = N - 1; i >= 0; i--){
			int c = N - i;
			if (total >= c){
				if (dp[i][cnt - 1][total - c]){
					ans.push_back(c);
					cnt--;
					total -= c;
				}
			}
		}
		reverse(ans.begin(), ans.end());
		for (int i = 0; i < K; i++){
			cout << ans[i];
			if (i < K - 1){
				cout << ' ' << endl;
			}
		}
	}
}
0