結果

問題 No.115 遠足のおやつ
ユーザー krotonkroton
提出日時 2014-12-10 21:08:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,289 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 147,080 KB
実行使用メモリ 8,928 KB
最終ジャッジ日時 2023-08-31 00:19:32
合計ジャッジ時間 4,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,612 KB
testcase_01 AC 4 ms
8,592 KB
testcase_02 AC 4 ms
8,836 KB
testcase_03 AC 5 ms
8,608 KB
testcase_04 AC 23 ms
8,672 KB
testcase_05 AC 5 ms
8,700 KB
testcase_06 AC 4 ms
8,596 KB
testcase_07 AC 5 ms
8,588 KB
testcase_08 AC 4 ms
8,592 KB
testcase_09 AC 4 ms
8,620 KB
testcase_10 AC 5 ms
8,612 KB
testcase_11 AC 5 ms
8,684 KB
testcase_12 AC 4 ms
8,608 KB
testcase_13 AC 4 ms
8,732 KB
testcase_14 AC 5 ms
8,624 KB
testcase_15 AC 12 ms
8,696 KB
testcase_16 AC 23 ms
8,692 KB
testcase_17 AC 9 ms
8,608 KB
testcase_18 AC 4 ms
8,588 KB
testcase_19 AC 5 ms
8,672 KB
testcase_20 AC 5 ms
8,700 KB
testcase_21 AC 4 ms
8,688 KB
testcase_22 AC 7 ms
8,592 KB
testcase_23 AC 4 ms
8,604 KB
testcase_24 AC 6 ms
8,612 KB
testcase_25 AC 9 ms
8,680 KB
testcase_26 AC 5 ms
8,668 KB
testcase_27 AC 5 ms
8,588 KB
testcase_28 AC 5 ms
8,928 KB
testcase_29 AC 7 ms
8,596 KB
testcase_30 AC 7 ms
8,604 KB
testcase_31 AC 5 ms
8,616 KB
testcase_32 AC 15 ms
8,592 KB
testcase_33 AC 5 ms
8,700 KB
testcase_34 AC 21 ms
8,612 KB
testcase_35 AC 7 ms
8,724 KB
testcase_36 AC 5 ms
8,600 KB
testcase_37 AC 18 ms
8,592 KB
testcase_38 AC 33 ms
8,732 KB
testcase_39 AC 33 ms
8,672 KB
testcase_40 AC 5 ms
8,668 KB
testcase_41 AC 4 ms
8,672 KB
testcase_42 AC 4 ms
8,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[111][1111][11];
bool can(int N, int last, int D, int K){
    if(K == 0){
        if(D == 0){
            return true;
        } else {
            return false;
        }
    }
    if(last == N || D <= 0){
        return false;
    }
    
    if(dp[last][D][K] != -1)return dp[last][D][K];
    
    bool res = false;
    for(int i=last+1;i<=N;i++){
        res |= can(N, i, D - i, K - 1);
    }
    
    return dp[last][D][K] = res;
}
vector<int> dp_solver(int N, int D, int K){
    memset(dp, -1, sizeof(dp));
    
    vector<int> res;
    if(!can(N, 0, D, K)){
        res.push_back(-1);
        return res;
    }
    
    int last = 0;
    for(int i=1;i<=K;i++){
        for(int j=last+1;j<=N;j++){
            if(can(N, j, D - j, K - i)){
                res.push_back(j);
                
                D -= j;
                last = j;
                break;
            }
        }
    }
    
    return res;
}

int main(){
    int N, D, K;
    cin >> N >> D >> K;
    
    auto res = dp_solver(N, D, K);
    for(int i=0;i<res.size();i++){
        if(i > 0){
            cout << " ";
        }
        cout << res[i];
    }
    cout << endl;
    
    return 0;
}
0