結果

問題 No.1701 half price
ユーザー atjh16atjh16
提出日時 2021-10-09 15:58:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 656 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 198,636 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 02:14:35
合計ジャッジ時間 3,058 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, w, m = 0;
int a[13];

int main()
{
	cin >> n >> w;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int j = 0; j < (1 << n); j++) {
		long long x = 0;

		for (int k = 0; k < n; k++) {
			if (j >> k & 1)
				x += a[k];

			if (x > w)
				break;
		}

		if (x == w)
			m++;
	}

	for(int i = 0; i < n; i++){
		for (int j = 0; j < (1 << (n - 1)); j++) {
			long long x = 0;

			for (int k = 0; k < n - 1; k++) {
				if (j >> k & 1) {
					if (k < i)
						x += a[k];
					else
						x += a[k + 1];
				}

				if (x > w)
					break;
			}

			if (x + a[i] / 2 == w)
				m++;
		}
	}

	cout << m << endl;
}

0