結果

問題 No.115 遠足のおやつ
ユーザー beetbeet
提出日時 2018-10-05 16:58:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 687 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 165,684 KB
実行使用メモリ 12,448 KB
最終ジャッジ日時 2023-08-31 00:47:44
合計ジャッジ時間 2,975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,116 KB
testcase_01 AC 4 ms
12,320 KB
testcase_02 AC 4 ms
12,448 KB
testcase_03 AC 3 ms
12,164 KB
testcase_04 AC 5 ms
12,248 KB
testcase_05 AC 3 ms
12,124 KB
testcase_06 AC 3 ms
12,112 KB
testcase_07 AC 4 ms
12,316 KB
testcase_08 AC 4 ms
12,112 KB
testcase_09 AC 4 ms
12,392 KB
testcase_10 AC 4 ms
12,108 KB
testcase_11 AC 4 ms
12,116 KB
testcase_12 AC 4 ms
12,244 KB
testcase_13 AC 4 ms
12,112 KB
testcase_14 AC 4 ms
12,124 KB
testcase_15 AC 5 ms
12,244 KB
testcase_16 AC 5 ms
12,244 KB
testcase_17 AC 4 ms
12,104 KB
testcase_18 AC 4 ms
12,396 KB
testcase_19 AC 4 ms
12,184 KB
testcase_20 AC 4 ms
12,168 KB
testcase_21 AC 5 ms
12,124 KB
testcase_22 AC 4 ms
12,120 KB
testcase_23 AC 3 ms
12,124 KB
testcase_24 AC 4 ms
12,120 KB
testcase_25 AC 4 ms
12,244 KB
testcase_26 AC 4 ms
12,392 KB
testcase_27 AC 4 ms
12,116 KB
testcase_28 AC 4 ms
12,184 KB
testcase_29 AC 4 ms
12,176 KB
testcase_30 AC 4 ms
12,164 KB
testcase_31 AC 3 ms
12,184 KB
testcase_32 AC 5 ms
12,164 KB
testcase_33 AC 4 ms
12,392 KB
testcase_34 AC 5 ms
12,128 KB
testcase_35 AC 4 ms
12,108 KB
testcase_36 AC 4 ms
12,188 KB
testcase_37 AC 5 ms
12,172 KB
testcase_38 AC 6 ms
12,164 KB
testcase_39 AC 6 ms
12,312 KB
testcase_40 AC 3 ms
12,124 KB
testcase_41 AC 4 ms
12,180 KB
testcase_42 AC 3 ms
12,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int n,d,k;
Int dp[101][1010][11];
Int dfs(Int x,Int y,Int z){
  Int &res=dp[x][y][z];
  if(~res) return res;
  if(x==n) return res=(y==d&&z==k);
  res=0;
  res|=dfs(x+1,y,z);
  if(y+(x+1)<=d&&z+1<=k) res|=dfs(x+1,y+(x+1),z+1);
  return res;
}

void dfs2(Int x,Int y,Int z){
  if(x==n) return;
  if(y+(x+1)<=d&&z+1<=k&&dfs(x+1,y+(x+1),z+1)){
    if(y) cout<<" ";
    cout<<x+1;
    dfs2(x+1,y+(x+1),z+1);
    return;
  }
  dfs2(x+1,y,z);
}

signed main(){
  cin>>n>>d>>k;
  memset(dp,-1,sizeof(dp));
  if(!dfs(0,0,0)){
    cout<<-1<<endl;
    return 0;
  }
  dfs2(0,0,0);
  cout<<endl;
  return 0;
}
0