結果

問題 No.1701 half price
ユーザー monnumonnu
提出日時 2021-10-15 20:28:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 3,000 ms
コード長 873 bytes
コンパイル時間 4,887 ms
コンパイル使用メモリ 229,320 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 19:37:21
合計ジャッジ時間 4,852 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000
#define MOD 998244353
#define MAX 200000


int main(){
  int N;
  ll W;
  cin>>N>>W;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  vector<ll> full_price(1<<N,0);
  vector<ll> half_price(1<<N,0);
  for(int bit=1;bit<(1<<N);bit++){
    ll sum=0;
    for(int i=0;i<N;i++){
      if(((bit>>i)&1)==1){
        sum+=a[i];
      }
    }
    full_price[bit]=sum;
    half_price[bit]=sum/2;
  }
  int ans=0;
  //cout<<W<<endl;
  for(int bit=1;bit<(1<<N);bit++){
    bool flag=false;
    for(int s=bit;;s=((s-1)&bit)){
      if(half_price[s]+full_price[s^bit]==W){
        flag=true;
      }
      if(s==0){
        break;
      }
    }
    if(flag){
      ans++;
    }
  }
  cout<<ans<<'\n';
}
0