結果

問題 No.1701 half price
ユーザー titan23
提出日時 2022-07-03 04:13:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 734 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 199,952 KB
最終ジャッジ日時 2025-01-30 04:05:57
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 4 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n, w;
  cin >> n >> w;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];

  set<int> ans;
  for (int i = 0; i < (1<<n); i++) {
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) A[j] /= 2;
    }

    for (int k = 0; k < (1<<n); k++) {
      long long tmp = 0;
      for (int j = 0; j < n; j++) {
        if ((k >> j) & 1) tmp += A[j];
      }
      if (tmp == w) {
        ans.insert(k);
      }
    }

    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) A[j] *= 2;
    }

  }
  cout << ans.size() << endl;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
0