結果

問題 No.1701 half price
ユーザー tnakao0123tnakao0123
提出日時 2021-10-09 00:43:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 31,908 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 15:29:07
合計ジャッジ時間 1,459 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1701.cc:  No.1701 half price - yukicoder
 */

#include<cstdio>
 
using namespace std;

/* constant */

const int MAX_N = 13;
const int NBITS = 1 << MAX_N;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int nbits = 1 << n, cnt = 0;
  for (int bits = 0; bits < nbits; bits++) {
    ll sum = 0;
    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (bits & bi) sum += as[i];
    if (sum == w) cnt++;

    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (bits & bi) {
	ll sumi = sum - as[i] / 2;
	if (sumi == w) cnt++;
      }
  }

  printf("%d\n", cnt);
  return 0;
}
0