結果

問題 No.3634 Made to order
コンテスト
ユーザー abc864197532
提出日時 2026-08-21 22:33:51
言語 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  
実行時間 107 ms / 2,000 ms
+ 39µs
コード長 2,485 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,550 ms
コンパイル使用メモリ 341,636 KB
実行使用メモリ 9,412 KB
最終ジャッジ日時 2026-08-21 22:34:28
合計ジャッジ時間 5,512 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_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;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector <T> vec) {
    o << "{"; int f = 0;
    for (T i : vec) o << (f++ ? " " : "") << i;
    return o << "}";
}
void bug__(int c, auto ...a) {
    cerr << "\e[1;" << c << "m";
    (..., (cerr << a << " "));
    cerr << "\e[0m" << endl;
}
#define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x)
#define bug(x...) bug_(32, x)
#define bugv(x...) bug_(36, vector(x))
#define safe bug_(33, "safe")
#else
#define bug(x...) void(0)
#define bugv(x...) void(0)
#define safe void(0)
#endif
const int mod = 998244353, N = 300005;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n, d;
    cin >> n >> d;
    vector <array <int, 3>> arr(n);
    int tot0 = 0, tot2 = 0;
    for (auto &[a, b, c] : arr) cin >> a >> b >> c, tot0 += a, tot2 += c;
    vector <int> mnl(1 << n, 1 << 30), mnr(1 << n, 1 << 30);
    for (int s = 0; s < 1 << n; ++s) if (__builtin_popcount(s) == n / 2) {
        vector <int> ord;
        for (int i = 0; i < n; ++i) if (s >> i & 1) {
            ord.pb(i);
        }
        do {
            int x = 0, y = 0, z = 0, cur2 = 0;
            for (int i : ord) {
                x += arr[i][0];
                y = max(x, y) + arr[i][1];
                z = max(y, z) + arr[i][2];
                cur2 += arr[i][2];
            }
            if (z + tot2 - cur2 <= d) {
                mnl[s] = min(mnl[s], y);
            }
        } while (next_permutation(all(ord)));
    }
    for (int s = 0; s < 1 << n; ++s) if (__builtin_popcount(s) == (n + 1) / 2) {
        vector <int> ord;
        for (int i = 0; i < n; ++i) if (s >> i & 1) {
            ord.pb(i);
        }
        do {
            int x = 0, y = 0, z = 0, cur0 = 0;
            for (int i : ord) {
                z += arr[i][2];
                y = max(y, z) + arr[i][1];
                x = max(x, y) + arr[i][0];
                cur0 += arr[i][0];
            }
            if (x + tot0 - cur0 <= d) {
                mnr[s] = min(mnr[s], y);
            }
        } while (next_permutation(all(ord)));
    }
    for (int s = 0; s < 1 << n; ++s) if (__builtin_popcount(s) == n / 2) {
        if (mnl[s] <= d - mnr[s ^ ((1 << n) - 1)]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}
0