結果

問題 No.2686 商品券の使い道
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-03-26 13:29:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 3,000 ms
コード長 1,428 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 205,236 KB
実行使用メモリ 44,316 KB
最終ジャッジ日時 2024-03-26 13:29:54
合計ジャッジ時間 7,181 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 38 ms
13,568 KB
testcase_03 AC 37 ms
13,568 KB
testcase_04 AC 37 ms
13,568 KB
testcase_05 AC 36 ms
13,568 KB
testcase_06 AC 36 ms
13,568 KB
testcase_07 AC 37 ms
13,568 KB
testcase_08 AC 37 ms
13,568 KB
testcase_09 AC 36 ms
13,568 KB
testcase_10 AC 37 ms
13,568 KB
testcase_11 AC 37 ms
13,568 KB
testcase_12 AC 37 ms
13,568 KB
testcase_13 AC 35 ms
13,568 KB
testcase_14 AC 35 ms
13,568 KB
testcase_15 AC 37 ms
13,568 KB
testcase_16 AC 37 ms
13,568 KB
testcase_17 AC 36 ms
13,568 KB
testcase_18 AC 36 ms
13,568 KB
testcase_19 AC 37 ms
13,568 KB
testcase_20 AC 37 ms
13,568 KB
testcase_21 AC 37 ms
13,568 KB
testcase_22 AC 37 ms
13,568 KB
testcase_23 AC 35 ms
13,568 KB
testcase_24 AC 37 ms
13,568 KB
testcase_25 AC 37 ms
13,568 KB
testcase_26 AC 36 ms
13,568 KB
testcase_27 AC 35 ms
13,568 KB
testcase_28 AC 36 ms
13,568 KB
testcase_29 AC 140 ms
44,316 KB
testcase_30 AC 138 ms
44,316 KB
testcase_31 AC 140 ms
44,316 KB
testcase_32 AC 138 ms
44,316 KB
testcase_33 AC 138 ms
44,316 KB
testcase_34 AC 139 ms
44,316 KB
testcase_35 AC 139 ms
44,316 KB
testcase_36 AC 138 ms
44,316 KB
testcase_37 AC 138 ms
44,316 KB
testcase_38 AC 138 ms
44,316 KB
testcase_39 AC 138 ms
44,316 KB
testcase_40 AC 140 ms
44,316 KB
testcase_41 AC 136 ms
44,316 KB
testcase_42 AC 141 ms
44,316 KB
testcase_43 AC 138 ms
44,316 KB
testcase_44 AC 138 ms
44,316 KB
testcase_45 AC 138 ms
44,316 KB
testcase_46 AC 138 ms
44,316 KB
evil_random20_1.txt AC 137 ms
44,316 KB
evil_random20_2.txt AC 139 ms
44,316 KB
evil_random20_3.txt AC 139 ms
44,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    long long m, q;
    cin >> n >> m >> q;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<long long> asum(1 << n), bsum(1 << n);
    vector<long long> f(1 << n), g(1 << n);
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                asum[i] += a[j];
                bsum[i] += b[j];
            }
        }
        if (asum[i] <= m) {
            f[i] = 1;
        }
        if (asum[i] <= q) {
            g[i] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int x = 0; x < (1 << n); x++) {
            if (x & (1 << i)) {
                f[x] += f[x ^ (1 << i)];
                g[x] += g[x] + g[x ^ (1 << i)];
            }
        }
    }
    vector<long long> h(1 << n);
    for (int i = 0; i < (1 << n); i++) {
        h[i] = f[i] * g[i];
    }
    for (int i = 0; i < n; i++) {
        for (int x = 0; x < (1 << n); x++) {
            if (x & (1 << i)) {
                h[x] = h[x] - h[x ^ (1 << i)];
            }
        }
    }
    long long ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        if (h[i] > 0) {
            ans = max(ans, bsum[i]);
        }
    }
    cout << ans << endl;
}
0