結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2015-08-06 21:50:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 1,061 bytes |
コンパイル時間 | 747 ms |
コンパイル使用メモリ | 83,360 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-03 01:05:43 |
合計ジャッジ時間 | 2,026 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
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 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; }