結果

問題 No.1701 half price
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 15:40:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 3,000 ms
コード長 864 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 110,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 07:57:19
合計ジャッジ時間 3,078 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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