結果

問題 No.15 カタログショッピング
ユーザー latte0119latte0119
提出日時 2016-03-13 01:35:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,256 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 180,540 KB
実行使用メモリ 12,172 KB
最終ジャッジ日時 2023-10-26 03:16:23
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 55 ms
12,168 KB
testcase_06 AC 62 ms
12,156 KB
testcase_07 AC 72 ms
12,172 KB
testcase_08 AC 65 ms
12,144 KB
testcase_09 AC 65 ms
12,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N,S;
int P[44];

signed main(){
    cin>>N>>S;
    rep(i,N)cin>>P[i];

    map<int,vint>M;
    int n=N/2;int nn=N-n;
    rep(i,1<<n){
        int sum=0;
        rep(j,n)if(i>>j&1)sum+=P[j];
        M[sum].pb(i);
    }

    vector<vint>ans;
    rep(i,1<<nn){
        int sum=0;
        rep(j,nn)if(i>>j&1)sum+=P[n+j];
        vint &v=M[S-sum];
        for(int b:v){
            vint hoge;
            rep(j,n)if(b>>j&1)hoge.pb(j);
            rep(j,nn)if(i>>j&1)hoge.pb(j+n);
            ans.pb(hoge);
        }
    }

    sort(all(ans));
    rep(i,ans.size()){
        rep(j,ans[i].size()){
            if(j)cout<<" ";
            cout<<ans[i][j]+1;
        }cout<<endl;
    }
    return 0;
}
0