結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-12 18:42:31 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 72 ms / 5,000 ms | 
| コード長 | 1,124 bytes | 
| コンパイル時間 | 3,195 ms | 
| コンパイル使用メモリ | 216,672 KB | 
| 実行使用メモリ | 13,696 KB | 
| 最終ジャッジ日時 | 2025-05-12 18:42:35 | 
| 合計ジャッジ時間 | 3,882 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,S; cin >> N >> S;
    if(N == 1){cout << 1 << endl; return 0;}
    int n = N/2,m = N-n;
    vector<int> A(n),B(m);
    for(auto &a : A) cin >> a;
    for(auto &a : B) cin >> a;
    int n2 = 1<<n,m2 = 1<<m;
    map<int,vector<vector<int>>> As;
    vector<vector<int>> answer;
    for(int i=0; i<n2; i++){
        int now = 0;
        vector<int> P;
        for(int k=0; k<n; k++) if(i&(1<<k)) P.push_back(k),now += A.at(k);
        As[now].emplace_back(P);
    }
    for(int i=0; i<m2; i++){
        int now = 0;
        vector<int> Q;
        for(int k=0; k<m; k++) if(i&(1<<k)) Q.push_back(n+k),now += B.at(k);
        for(auto v : As[S-now]){
            vector<int> ans = v;
            for(auto q : Q) ans.push_back(q);
            answer.emplace_back(ans);        
        }
    }
    sort(answer.begin(),answer.end());
    for(auto &a : answer){
        for(int i=0; i<a.size(); i++){
            if(i) cout << " ";
            cout << a.at(i)+1;
        }
        cout << endl;
    }
}
            
            
            
        