結果
| 問題 | 
                            No.115 遠足のおやつ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             goodbaton
                         | 
                    
| 提出日時 | 2015-08-06 21:47:39 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,047 bytes | 
| コンパイル時間 | 527 ms | 
| コンパイル使用メモリ | 74,900 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-18 03:45:31 | 
| 合計ジャッジ時間 | 1,510 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 WA * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%d%d%d",&n,&d,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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 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,s+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;
}
            
            
            
        
            
goodbaton