結果

問題 No.15 カタログショッピング
ユーザー ytftytft
提出日時 2021-03-03 07:25:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 777 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 168,132 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2024-04-14 05:50:25
合計ジャッジ時間 8,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 lp=pow(2,n);
    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;
        }
        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];
            }
        }
    }
}
0