結果
問題 | No.1701 half price |
ユーザー |
![]() |
提出日時 | 2021-10-09 01:43:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 3,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 32,128 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 10:54:20 |
合計ジャッジ時間 | 1,129 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
/* -*- 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];ll bss[NBITS];/* 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;for (int bits = 1, msb = 1, msi = 0; bits < nbits; bits++) {if ((msb << 1) <= bits) msb <<= 1, msi++;bss[bits] = bss[bits ^ msb] + as[msi];}int cnt = 0;for (int bits = 1; bits < nbits; bits++) {bool found = false;for (int bits0 = bits;; bits0 = (bits0 - 1) & bits) {ll sum = bss[bits0] / 2 + bss[bits ^ bits0];if (sum == w) { found = true; break; }if (bits0 == 0) break;}if (found) cnt++;}printf("%d\n", cnt);return 0;}