結果

問題 No.1701 half price
ユーザー zezerozezero
提出日時 2021-10-08 23:25:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 3,000 ms
コード長 827 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 118,152 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 13:25:00
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int n;
set<ll> st;
map<ll,int> mp;
vector<ll> a;

void dfs(int bit,ll w,int d){
    if (d == n){
        st.insert(w);
        return;
    }
    if (bit & 1 << d) {
        dfs(bit,w+a[d],d+1);
        dfs(bit,w+a[d]/2,d+1);
    }
    else{
        dfs(bit,w,d+1);
    }
}

int main(){
    ll w;
    cin >> n >> w;
    a.resize(n);
    rep(i,n) cin >> a[i];
    for (int bit = 1; bit < (1 << n);bit++){
        st.clear();
        dfs(bit,0,0);
        for (auto q:st){
            mp[q]++;
        }
    }
    cout << mp[w] << endl;
    
    return 0;
}
0