結果

問題 No.1701 half price
ユーザー simansiman
提出日時 2021-10-11 11:23:54
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 3,000 ms
コード長 877 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 104,328 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-13 12:01:12
合計ジャッジ時間 3,961 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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) {
  ll cnt = 0;
  if (w > W) return 0;
  if (w == W && mask > 0) {
    if (not checked[mask]) {
      checked[mask] = true;
      cnt += 1;
    }
  }
  if (i == N) return cnt;

  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