結果

問題 No.15 カタログショッピング
ユーザー OnjuOnju
提出日時 2015-02-12 05:10:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 784 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 63,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 23:53:45
合計ジャッジ時間 1,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:8: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
      ++f;
        ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <vector>
#define N_MAX 31
#define S_MAX 310000000
#define P_MAX 10000000
using namespace std;

int main()
{
	int N, S, P[N_MAX];
	vector<int> ans;
	cin >> N >> S;

	for (int i = 0; i < N; ++i)
		cin >> P[i];

	int bmax = (1 << N) - 1;
	for (int b = 0; b <= bmax; ++b)
	{
		int temp = S;
		for (int i = 0; i < N; ++i)
		{
			if (b & (1 << i))
				temp -= P[i];
			if (temp < 0)
				break;
		}
		if (!temp)
			ans.push_back(b);
	}

	for (auto it = ans.begin(); it != ans.end(); ++it)
	{
		bool f = false;
		for (int i = 0; i < N_MAX; ++i)
		{
			if ((*it)& (1 << i))
			{
				if (f)
					cout << ' ' << i+1;
				else
				{
					cout << i+1;
					++f;
				}
			}
		}
		cout << endl;
	}

	return 0;
}
0