結果

問題 No.115 遠足のおやつ
ユーザー goodbatongoodbaton
提出日時 2015-08-06 21:50:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,061 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 74,276 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-31 00:34:22
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000009
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define PI 3.1415926536

#define SIZE 1024

bool dp[11][1001][101];

int n,d,k;
vector<int> ans;

bool dfs(int h,int c,int s){
    
    if(h==k){
        if(c==d)
            return false;
        return dp[h][c][s] = true;
    }
    
    if(s==n+1)
        return true;
    
    if(dp[h][c][s]) return true;
    
    for(int i=s;i<=n;i++){
        if(!dfs(h+1,c+i,i+1)){
            ans.push_back(i);
            return false;
        }
    }
    
    return dp[h][c][s]=true;
    
}

int main(){
    
    scanf("%d%d%d",&n,&d,&k);
    
    if(dfs(0,0,1)){
        puts("-1");
        return 0;
    }
    
    for(int i=0;i<k;i++){
        printf(i!=k-1 ? "%d " : "%d\n",ans[ans.size()-1-i]);
    }
    
    return 0;
}
0