結果

問題 No.15 カタログショッピング
ユーザー kosakkunkosakkun
提出日時 2016-11-08 19:01:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,057 bytes
コンパイル時間 1,167 ms
コンパイル使用メモリ 113,312 KB
実行使用メモリ 53,012 KB
最終ジャッジ日時 2023-08-16 15:27:21
合計ジャッジ時間 8,012 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <list>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(long long (i)=0;(i)<(long long)(n);(i)++)
#define RREP(i,n) for(long long (i)=(long long)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

map< ll, set<ll> > M1;
map< ll, set<ll> > M2;


int main(){
    
    ll N,S; cin>>N>>S;
    vector<ll> P1,P2;
    
    REP(i,N){
        ll t; cin>>t;
        if(i<N/2)P1.push_back(t);
        else P2.push_back(t);
    }
    
    for(int i=0;i<(1<<P1.size());i++){
        set<ll> t;
        ll sum=0;
        REP(j,P1.size()){
            if((i>>j)&1){
                sum+=P1[j];
                t.insert(j+1);
            }
        }
        M1[sum]=t;
    }
    
    for(int i=0;i<(1<<P2.size());i++){
        set<ll> t;
        ll sum=0;
        REP(j,P2.size()){
            if((i>>j)&1){
                sum+=P2[j];
                t.insert(j+N/2+1);
            }
        }
        M2[sum]=t;
    }
    
    vector< set<ll> > ans;
    for(auto itr1=M1.begin();itr1!=M1.end();itr1++){
        for(auto itr2=M2.begin();itr2!=M2.end();itr2++){
            ll sum=itr1->first+itr2->first;
            if(sum==S){
                set<ll> t=itr1->second;
                for(auto j=itr2->second.begin();j!=itr2->second.end();j++){
                    t.insert(*j);
                }
                ans.push_back(t);
            }
        }
    }
    
    vector<ll> anst;
    REP(i,ans.size()){
        set<ll> t=ans[i];
        for(auto i=t.begin();i!=t.end();i++){
            anst.push_back(*i);
        }
    }
    
    REP(i,anst.size()-1){
        cout<<anst[i]<<" ";
    }
    cout<<anst[anst.size()-1]<<endl;
    
    return 0;
}

0