結果

問題 No.1701 half price
ユーザー titan23titan23
提出日時 2022-07-03 04:13:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 734 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 204,560 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 23:59:36
合計ジャッジ時間 15,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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