結果
| 問題 | 
                            No.115 遠足のおやつ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2014-12-29 14:50:10 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 512 bytes | 
| コンパイル時間 | 413 ms | 
| コンパイル使用メモリ | 38,784 KB | 
| 実行使用メモリ | 9,632 KB | 
| 最終ジャッジ日時 | 2024-06-13 01:02:57 | 
| 合計ジャッジ時間 | 10,551 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 TLE * 1 -- * 4 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d%d%d",&n,&d,&k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <vector>
#include <cstdio>
#include <cstdlib>
using namespace std;
void dfs(vector<int>&v,int s,int t,int i,int n,int d,int k){
	if(d==k-1){
		int x=t-s;
		if(i<=x&&x<=n){
			for(int j=0;j<v.size();j++)printf("%d ",v[j]);
			printf("%d\n",x);
			exit(0);
		}
	}else{
		for(;i<=n;i++){
			if(s+(k-d)*(2*i+(k-d-1))/2<=t){
				v.push_back(i);
				dfs(v,s+i,t,i+1,n,d+1,k);
				v.pop_back();
			}
		}
	}
}
int main(){
	int n,d,k;
	scanf("%d%d%d",&n,&d,&k);
	vector<int>v;
	dfs(v,0,d,1,n,0,k);
	puts("-1");
}