結果

問題 No.1701 half price
ユーザー ktr216ktr216
提出日時 2021-10-08 22:09:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 3,000 ms
コード長 732 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 169,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 10:25:10
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 15 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 133 ms
4,376 KB
testcase_07 AC 132 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 44 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 133 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];
    int x = 1;
    rep(i, 0, N) x *= 3;
    vector<bool> ok(1 << N, false);
    rep(i, 1, x) {
        ll s = 0, y = i, b = 0;
        rep(j, 0, N) {
            int r = y % 3;
            y /= 3;
            b *= 2;
            if (r == 1) s += a[j] / 2;
            if (r == 2) s += a[j];
            if (r > 0) b++;
        }
        //cout << i << " " << s << endl;
        if (s == W) {
            ok[b] = true;
        }
    }
    int ans = 0;
    rep(i, 0, 1 << N) ans += ok[i];
    cout << ans << endl;
}
0