結果

問題 No.115 遠足のおやつ
ユーザー latte0119latte0119
提出日時 2016-01-13 19:03:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,059 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 148,008 KB
実行使用メモリ 12,372 KB
最終ジャッジ日時 2023-08-31 00:37:01
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,108 KB
testcase_01 AC 4 ms
12,036 KB
testcase_02 AC 4 ms
12,108 KB
testcase_03 AC 4 ms
12,104 KB
testcase_04 AC 5 ms
12,064 KB
testcase_05 AC 4 ms
12,052 KB
testcase_06 AC 4 ms
12,044 KB
testcase_07 AC 4 ms
12,096 KB
testcase_08 AC 4 ms
12,048 KB
testcase_09 AC 4 ms
12,068 KB
testcase_10 AC 4 ms
12,256 KB
testcase_11 AC 4 ms
12,372 KB
testcase_12 AC 4 ms
12,120 KB
testcase_13 AC 4 ms
12,372 KB
testcase_14 AC 4 ms
12,108 KB
testcase_15 AC 5 ms
12,260 KB
testcase_16 AC 5 ms
12,252 KB
testcase_17 AC 5 ms
12,168 KB
testcase_18 AC 4 ms
12,040 KB
testcase_19 AC 5 ms
12,320 KB
testcase_20 AC 5 ms
12,260 KB
testcase_21 AC 5 ms
12,104 KB
testcase_22 AC 5 ms
12,168 KB
testcase_23 AC 5 ms
12,036 KB
testcase_24 AC 4 ms
12,060 KB
testcase_25 AC 5 ms
12,104 KB
testcase_26 AC 4 ms
12,172 KB
testcase_27 AC 4 ms
12,252 KB
testcase_28 AC 4 ms
12,048 KB
testcase_29 AC 4 ms
12,064 KB
testcase_30 AC 4 ms
12,056 KB
testcase_31 AC 4 ms
12,108 KB
testcase_32 AC 4 ms
12,128 KB
testcase_33 AC 4 ms
12,168 KB
testcase_34 AC 4 ms
12,056 KB
testcase_35 AC 5 ms
12,116 KB
testcase_36 AC 4 ms
12,180 KB
testcase_37 AC 4 ms
12,056 KB
testcase_38 AC 6 ms
12,148 KB
testcase_39 AC 6 ms
12,052 KB
testcase_40 AC 4 ms
12,256 KB
testcase_41 AC 5 ms
12,040 KB
testcase_42 AC 4 ms
12,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

int dp[101][1001][11];

signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    memset(dp,-1,sizeof(dp));
    dp[0][0][0]=0;

    int N,D,K;cin>>N>>D>>K;
    reps(i,1,N+1){
        rep(j,D+1){
            rep(k,K+1){
                if(~dp[i-1][j][k])dp[i][j][k]=0;
                if(k&&j-i>=0&&~dp[i-1][j-i][k-1])dp[i][j][k]=1;
            }
        }
    }

    if(dp[N][D][K]==-1)cout<<-1<<endl;
    else{
        vint ans;
        int d=D,k=K;
        for(int i=N;i>0;i--){
            if(dp[i][d][k]){
                ans.pb(i);
                d-=i;
                k--;
            }
        }
        reverse(all(ans));
        rep(i,ans.size()){
            if(i)cout<<" ";
            cout<<ans[i];
        }cout<<endl;
    }
    return 0;
}
0