結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー a01sa01to
提出日時 2025-12-12 00:48:54
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 975 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,945 ms
コンパイル使用メモリ 281,756 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-12 00:48:59
合計ジャッジ時間 4,839 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, d, k;
  cin >> n >> d >> k;
  vector dp(d + 1, vector<int>(k + 1, -1));
  dp[0][0] = 0;
  for (int p = 1; p <= n; ++p) {
    for (int i = d; i >= 0; --i) {
      for (int j = k - 1; j >= 0; --j) {
        if (dp[i][j] == -1) continue;
        if (i + p <= d) {
          dp[i + p][j + 1] = i;
          break;
        }
      }
    }
  }
  if (dp[d][k] == -1) {
    cout << -1 << '\n';
  }
  else {
    vector<int> ans;
    int cur = d;
    for (int x = k; x > 0; --x) {
      // cerr << cur << ' ' << x << ' ' << dp[cur][x] << '\n';
      ans.push_back(cur - dp[cur][x]);
      cur = dp[cur][x];
    }
    reverse(ans.begin(), ans.end());
    assert(is_sorted(ans.begin(), ans.end()));
    rep(i, k) cout << ans[i] << ' ';
    cout << '\n';
  }
  return 0;
}
0