結果

問題 No.1701 half price
ユーザー mmn15277198mmn15277198
提出日時 2021-10-09 10:40:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 3,000 ms
コード長 794 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 104,540 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-01 05:53:40
合計ジャッジ時間 2,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 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,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 76 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

int n;
long long w;
vector<long long> a;
map<vector<int>,int> mp;
vector<int> v;
bool f = false;

void dfs(long long sum , int id) {
  //cout << id << " " << sum << endl;
  if (id >= n) {
    if (sum == w) {
      if (f) mp[v]++;
    }
    return;
  }
  dfs(sum , id + 1);
  v.push_back(id);
  f = true;
  dfs(sum + a[id] , id + 1);
  v.pop_back();
  v.push_back(id);
  f = true;
  dfs(sum + a[id] / 2 , id + 1);
  v.pop_back();
  return;
}

int main() {
  cin >> n >> w;
  a = vector<long long>(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0,0);
  cout << mp.size() << endl;
  return 0;
}
0