結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-03 15:21:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 5,000 ms |
| コード長 | 1,528 bytes |
| コンパイル時間 | 1,440 ms |
| コンパイル使用メモリ | 103,560 KB |
| 実行使用メモリ | 16,596 KB |
| 最終ジャッジ日時 | 2024-12-17 13:44:37 |
| 合計ジャッジ時間 | 2,457 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int main(){
int n, s;
cin >> n >> s;
vector<int> v(n);
for(int i = 0; i < n; i++) cin >> v[i];
vector<pair<int,set<int>>> vp;
int n1 = n/2;
for(int i = 0; i < 1<<n1; i++){
set<int> tmp;
int tmpval = 0;
for(int j = 0; j < n1; j++){
if((i>>j)&1){
tmp.insert(j+1);
tmpval += v[j];
}
}
vp.push_back({tmpval, tmp});
}
sort(vp.begin(), vp.end());
vector<set<int>> ans;
for(int i = 0; i < 1<<(n-n1); i++){
set<int> tmp;
int tmpval = 0;
for(int j = 0; j < n-n1; j++){
if((i>>j)&1){
tmp.insert(n1+j+1);
tmpval += v[n1+j];
}
}
if(tmpval > s) continue;
set<int> emp;
int l = lower_bound(vp.begin(), vp.end(), make_pair(s-tmpval, emp)) - vp.begin();
int r = lower_bound(vp.begin(), vp.end(), make_pair(s-tmpval+1, emp)) - vp.begin();
r--;
while(l <= r){
set<int> copy = vp[l].second;
copy.insert(tmp.begin(), tmp.end());
ans.push_back(copy);
l++;
}
}
sort(ans.begin(), ans.end());
for(set<int> t : ans){
for(auto it = t.begin(); it != t.end(); it++){
if(it != t.begin()) cout << " ";
cout << *it;
}
cout << endl;
}
return 0;
}