結果

問題 No.115 遠足のおやつ
ユーザー kappybarkappybar
提出日時 2020-03-28 11:42:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,179 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 172,688 KB
実行使用メモリ 7,668 KB
最終ジャッジ日時 2023-08-31 00:57:43
合計ジャッジ時間 2,887 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
    int n,d,k;
    cin >> n >> d >> k;
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(k+1,vector<int>(d+1,0)));
    dp[0][0][0] = 1;
    for(int i =1;i <=n;i++){
        rep(cnt,k+1)rep(value,d+1){
            dp[i][cnt][value] += dp[i-1][cnt][value];
            if(value - i >= 0 && cnt -1 >= 0){
                dp[i][cnt][value] += dp[i-1][cnt-1][value-i];
            }
        }
    }

    if(dp[n][k][d] <= 0){
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    int now = n,cnt = k,value = d;
    while(now >= 0){
        if(cnt - 1 >= 0 && value - now >= 0){
            if(dp[now-1][cnt-1][value-now] > 0){
                ans.push_back(now);
                value -= now;now --;cnt --;
            }
            else{
                now --;
            }
        }
        else{
            now --;
        }
    }

    reverse(ans.begin(),ans.end());
    rep(i,ans.size()) cout << ans[i] <<  " ";
    cout << endl;
    return 0;  
}
0