結果

問題 No.1701 half price
ユーザー asaringoasaringo
提出日時 2021-10-08 22:21:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 3,000 ms
コード長 807 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 169,104 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 10:46:55
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)

ll w ;
int n ;

ll A[20] ;

int main(){
    cin >> n >> w ;
    rep(i,n) cin >> A[i] ;
    ll res = 0 ;
    rep(S,1<<n){
        if(S == 0) continue ;
        vector<ll> vec ;
        rep(i,n) if(S >> i & 1) vec.push_back(A[i]) ;
        int m = vec.size() ;
        bool ok = false ;
        rep(T,1<<m){
            vector<ll> tor ;
            rep(i,m) {
                if(T >> i & 1) tor.push_back(vec[i] / 2) ;
                else tor.push_back(vec[i]) ;
            }
            ll sum = 0 ;
            rep(i,m) sum += tor[i] ;
            if(sum == w) ok = true ;
        }
        if(ok) res++ ;
    }
    cout << res << endl ;
}
0