結果

問題 No.3634 Made to order
コンテスト
ユーザー 👑 ssmbc2929_bartok
提出日時 2026-06-01 11:56:12
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 7 ms / 2,000 ms
+ 119µs
コード長 1,422 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,098 ms
コンパイル使用メモリ 346,444 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-22 00:26:43
合計ジャッジ時間 5,636 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
サブタスク $1$ 20 % AC * 8
サブタスク $2$ 10 % AC * 21
サブタスク $3$ 70 % AC * 26
合計 3 * 100% = 300 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  ll D;
  cin >> N >> D;
  vector<ll> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];

  int full = (1 << N) - 1;

  vector<ll> sumA(1 << N, 0);
  for (int S = 1; S <= full; S++) {
    int j = __builtin_ctz((unsigned)S);
    sumA[S] = sumA[S ^ (1 << j)] + A[j];
  }

  vector<vector<pair<ll, ll>>> dp(1 << N);
  dp[0].push_back({0LL, 0LL});

  auto reduce = [](vector<pair<ll, ll>>& v) {
    if (v.size() <= 1) return;
    sort(v.begin(), v.end());
    vector<pair<ll, ll>> res;
    ll best = LLONG_MAX;
    for (auto& p : v) {
      if (p.second < best) {
        res.push_back(p);
        best = p.second;
      }
    }
    v.swap(res);
  };

  ll ans = LLONG_MAX;
  for (int S = 0; S <= full; S++) {
    if (dp[S].empty()) continue;
    reduce(dp[S]);

    if (S == full) {
      for (auto& pr : dp[S]) ans = min(ans, pr.second);
      break;
    }

    for (int j = 0; j < N; j++) {
      if (S & (1 << j)) continue;
      int T = S | (1 << j);
      ll c1p = sumA[T];
      for (auto& pr : dp[S]) {
        ll c2p = max(pr.first, c1p) + B[j];
        ll c3p = max(pr.second, c2p) + C[j];
        dp[T].push_back({c2p, c3p});
      }
    }
    vector<pair<ll, ll>>().swap(dp[S]);  
  }

  cout << (ans <= D ? "Yes" : "No") << "\n";
  return 0;
}
0