結果

問題 No.15 カタログショッピング
ユーザー ytftytft
提出日時 2021-03-03 07:37:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,241 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 174,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 05:51:03
合計ジャッジ時間 29,381 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0