結果

問題 No.115 遠足のおやつ
ユーザー ngtkanangtkana
提出日時 2020-03-25 21:52:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 207,632 KB
実行使用メモリ 12,100 KB
最終ジャッジ日時 2023-08-31 00:57:39
合計ジャッジ時間 3,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,X,K;std::cin>>n>>X>>K;
    std::vector<std::vector<std::vector<lint>>>
        dp(n+1,std::vector<std::vector<lint>>(K+1,std::vector<lint>(X+1)));
    for(lint i=0;i<=n;i++){
        dp.at(i).at(0).at(0)=true;
    }
    std::vector<lint>a(n);
    std::iota(a.begin(),a.end(),1ll);
    for(lint i=n-1;i>=0;i--){
        for(lint j=1;j<=K;j++){
            for(lint k=a.at(i);k<=X;k++){
                dp.at(i).at(j).at(k)|=dp.at(i+1).at(j-1).at(k-a.at(i));
                dp.at(i).at(j).at(k)|=dp.at(i+1).at(j).at(k);
            }
        }
    }
    lint i=0,j=K,k=X;
    while(true){
        for(;i<n&&a.at(i)<=k&&!dp.at(i+1).at(j-1).at(k-a.at(i));i++);
        if(i==n||k<a.at(i)){
            std::cout<<-1<<'\n';
            return 0;
        }
        std::cout<<(j==K?"":" ")<<a.at(i);
        j--;
        k-=a.at(i++);
        if(j==0)break;
    }
    std::cout<<'\n';
}
0