結果

問題 No.15 カタログショッピング
ユーザー simezi_tansimezi_tan
提出日時 2015-07-22 19:32:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,098 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 165,656 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2023-09-22 21:19:13
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 35 ms
9,992 KB
testcase_06 AC 34 ms
10,144 KB
testcase_07 AC 35 ms
9,988 KB
testcase_08 AC 34 ms
10,060 KB
testcase_09 AC 36 ms
10,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n;
ll s, p[40];

int main(){
	cin >> n >> s;
	rep(i, n) cin >> p[i];
	
	if(n == 1){
		if(p[0] == s) cout << 1 << endl;
		return 0;
	}
	
	int m = n / 2;
	unordered_map<ll, vi> lst;
	vector<vi> ans;
	
	rep(i, 1 << m){
		
		ll sum = 0;
		rep(j, m) if(i & 1 << j) sum += p[j];
		lst[sum].pb(i);
	}
	
	rep(i, 1 << (n - m)){
		
		ll sum = 0;
		rep(j, n - m) if(i & 1 << j) sum += p[j + m];
		each(j, lst[s - sum]){
			
			vi v;
			rep(k, m) if(*j & 1 << k) v.pb(k + 1);
			rep(k, n - m) if(i & 1 << k) v.pb(k + m + 1);
			ans.pb(v);
		}
	}
	sort(all(ans));
	each(i, ans){
		rep(j, i->size()) printf("%d%c", (*i)[j], j==i->size()-1?'\n':' ');
	}
	
	return 0;
}
0