結果

問題 No.1701 half price
コンテスト
ユーザー siman
提出日時 2021-10-11 11:18:48
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 889 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,396 ms
コンパイル使用メモリ 148,864 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 18:48:28
合計ジャッジ時間 4,208 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
int N, W;
bool checked[1 << 13];

ll dfs(int i, int w, vector<int> &A, int mask) {
  if (w > W) return 0;
  if (w == W) {
    if (checked[mask]) {
      return 0;
    } else {
      checked[mask] = true;
      return 1;
    }
  }
  if (i == N) return 0;

  ll cnt = 0;

  cnt += dfs(i + 1, w, A, mask);
  cnt += dfs(i + 1, w + A[i], A, mask | (1 << i));
  cnt += dfs(i + 1, w + A[i] / 2, A, mask | (1 << i));

  return cnt;
}

int main() {
  memset(checked, false, sizeof(checked));
  cin >> N >> W;
  vector<int> A(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int mask = 0;
  cout << dfs(0, 0, A, mask) << endl;

  return 0;
}
0