結果

問題 No.15 カタログショッピング
ユーザー opqopq_opqopq_
提出日時 2015-05-14 10:35:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 54,984 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 07:41:21
合計ジャッジ時間 1,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define N_MAX 31
int N, S;
int P[N_MAX];
vector<vector<int>> res;

int main() {
	scanf("%d%d", &N, &S);
	for (int i = 0; i < N; i++) scanf("%d", P + i);
	
	for (int i = 0; i < 1 << N; i++) {
		vector<int> id;
		for (int j = 0; 1 << j <= i; j++) {
			if (i & 1 << j) id.push_back(j);
		}
		long long sum = 0;
		for (int& j : id) sum += P[j];
		if (sum == S) res.push_back(id);
	}
	
	sort(res.begin(), res.end());
	
	for (auto& v : res) {
		for (int i = 0; i < v.size(); i++) {
			printf("%d%c", v[i] + 1, i + 1 < v.size() ? ' ' : '\n');
		}
	}
	
	return 0;
}

0