結果

問題 No.15 カタログショッピング
ユーザー 沙耶花沙耶花
提出日時 2021-10-20 22:46:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 1,343 bytes
コンパイル時間 5,160 ms
コンパイル使用メモリ 282,888 KB
実行使用メモリ 18,836 KB
最終ジャッジ日時 2023-10-20 11:11:49
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 97 ms
18,832 KB
testcase_06 AC 96 ms
18,820 KB
testcase_07 AC 105 ms
18,836 KB
testcase_08 AC 101 ms
18,816 KB
testcase_09 AC 103 ms
18,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

void go(vector<pair<long long,int>> &a,long long sum,int ind,vector<int> inds,map<long long,vector<vector<int>>> &mp){
	if(ind==a.size()){
		mp[sum].push_back(inds);
		return;
	}
	go(a,sum,ind+1,inds,mp);
	inds.push_back(a[ind].second);
	go(a,sum + a[ind].first,ind+1,inds,mp);
	
}

int main(){
	
	int N;
	cin>>N;
	
	long long P;
	cin>>P;
	
	vector<pair<long long,int>> S(N);
	rep(i,N){
		cin>>S[i].first;
		S[i].second = i;;
	}
	vector<pair<long long,int>> T;
	
	while(S.size()>T.size()){
		T.push_back(S.back());
		S.pop_back();
	}
	
	map<long long,vector<vector<int>>> mp0,mp1;
	
	go(S,0,0,{},mp0);
	go(T,0,0,{},mp1);
	
	vector<vector<int>> ans;
	for(auto a:mp0){
		if(mp1.count(P - a.first)){
			auto t0 = a.second;
			auto t1 = mp1[P-a.first];
			rep(i,t0.size()){
				
				rep(j,t1.size()){
					auto temp = t0[i];
					rep(k,t1[j].size())temp.push_back(t1[j][k]);
					ans.push_back(temp);
				}
			}
		}
	}
	
	rep(i,ans.size())sort(ans[i].begin(),ans[i].end());
	
	sort(ans.begin(),ans.end());
	
	rep(i,ans.size()){
		rep(j,ans[i].size()){
			if(j!=0)cout<<' ';
			cout<<ans[i][j]+1;
		}
		cout<<endl;
	}
	
	
	return 0;
}
0