結果

問題 No.1701 half price
ユーザー srjywrdnprkt
提出日時 2023-06-03 15:40:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 137 ms / 3,000 ms
コード長 864 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 108,544 KB
最終ジャッジ日時 2025-02-13 22:21:49
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll N, W, M, ans=0, S;
    cin >> N >> W;
    M = 1<<N;
    vector<int> a(N);
    for (int i=0; i<N; i++) cin >> a[i];
    vector<bool> ok(M);
    for (int i=1; i<M; i++){
        for (int j=0; j<M; j++){
            if ((i & j) != j) continue;
            S = 0;
            for (int k=0; k<N; k++){
                if (1<<k & i){
                    if (1<<k & j) S += a[k]/2;
                    else S += a[k];
                }
            }
            if (S == W) ok[i] = 1;
        }
    }

    for (int i=0; i<M; i++) if (ok[i]) ans++;
    cout << ans << endl;

    return 0;
}
0