結果

問題 No.115 遠足のおやつ
ユーザー kk
提出日時 2020-06-05 19:36:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 962 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 200,484 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2023-08-31 00:59:25
合計ジャッジ時間 3,735 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
7,512 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
5,816 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,396 KB
testcase_15 AC 3 ms
7,324 KB
testcase_16 AC 4 ms
7,476 KB
testcase_17 AC 4 ms
7,440 KB
testcase_18 AC 3 ms
6,956 KB
testcase_19 AC 3 ms
6,936 KB
testcase_20 AC 3 ms
4,532 KB
testcase_21 AC 3 ms
5,976 KB
testcase_22 AC 3 ms
7,160 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
5,300 KB
testcase_25 AC 3 ms
7,608 KB
testcase_26 AC 2 ms
5,188 KB
testcase_27 AC 3 ms
7,124 KB
testcase_28 AC 2 ms
4,600 KB
testcase_29 AC 2 ms
6,568 KB
testcase_30 AC 3 ms
7,152 KB
testcase_31 AC 3 ms
6,196 KB
testcase_32 AC 3 ms
7,368 KB
testcase_33 AC 3 ms
6,392 KB
testcase_34 AC 4 ms
7,720 KB
testcase_35 AC 3 ms
6,572 KB
testcase_36 AC 3 ms
5,040 KB
testcase_37 AC 4 ms
7,420 KB
testcase_38 AC 4 ms
7,756 KB
testcase_39 AC 5 ms
7,720 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int n, d, k;
int dp[100+1][10+1][1000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  cin >> n >> d >> k;

  dp[n][1][n] = 1;
  dp[n][0][0] = 1;

  for (int i = n-1; i >= 0; i--) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= d; l++) {
        dp[i][j][l] = dp[i+1][j][l];
        if (j-1 >= 0 && l-i >= 0)
          dp[i][j][l] |= dp[i+1][j-1][l-i];
      }
    }
  }

  if (!dp[1][k][d]) {
    cout << -1 << endl;
  } else {
    vector<int> ret;
    for (int i = 1; i < n; i++) {
      if (dp[i+1][k-1][d-i]) {
        ret.push_back(i);
        --k;
        d -= i;
      }
    }
    if (k > 0)
      ret.push_back(n);
    for (auto &x: ret)
      cout << x << " ";
    cout << endl;
  }
  return 0;
}
0