結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  ytft | 
| 提出日時 | 2021-03-03 07:37:02 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,241 bytes | 
| コンパイル時間 | 1,957 ms | 
| コンパイル使用メモリ | 177,412 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-03 03:07:20 | 
| 合計ジャッジ時間 | 28,520 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 TLE * 5 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,s;
    cin>>n>>s;
    vector<long long> price(n);
    vector<bool> bought(n,true);
    long long current=0;
    for(int i=0;i<n;i++){
        cin>>price[i];
        current+=price[i];
    }
    long long sum=current;
    long long lp=pow(2,n-1);
    vector<vector<int>> ans={};
    vector<int> temp;
    for(long long j=0;j<lp;j++){
        if(current==s){
            for(int i=0;i<n;i++){
                if(bought[i]){
                    cout<<i+1<<" ";
                }
            }
            cout<<endl;
        }
        if(sum-current==s){
            temp={};
            for(int i=0;i<n;i++){
                if(!bought[i]){
                    temp.push_back(i+1);
                }
            }
            ans.push_back(temp);
        }
        for(int i=n-1;i>=0;i--){
            if(bought[i]){
                bought[i]=false;
                current-=price[i];
                break;
            }else{
                bought[i]=true;
                current+=price[i];
            }
        }
    }
    for(int i=ans.size()-1;i>=0;i--){
        for(int j=0;j<ans[i].size();j++){
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
}
            
            
            
        