結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2017-02-26 01:06:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 5,000 ms |
| コード長 | 1,415 bytes |
| コンパイル時間 | 1,640 ms |
| コンパイル使用メモリ | 182,924 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2024-06-11 15:32:23 |
| 合計ジャッジ時間 | 2,611 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
int main(){
int N;
ll SS;
cin >> N >> SS;
vector<ll> P(N);
rep(i,N){
cin >> P[i];
}
vector<ll> P1, P2;
rep(i,N/2){
P1.push_back(P[i]);
}
REP(i,N/2,N){
P2.push_back(P[i]);
}
map<ll,vector<ll> > memo1, memo2;
for(ll S=0; S<(1<<P1.size()); S++){
ll sum = 0;
rep(i,16){
if((S>>i)&1) sum += P1[i];
}
memo1[sum].push_back(S);
}
for(ll S=0; S<(1<<P2.size()); S++){
ll sum = 0;
rep(i,16){
if((S>>i)&1) sum += P2[i];
}
memo2[sum].push_back(S);
}
map<vector<int>,int> ret;
FOR(it,memo1){
if(memo2.count(SS - (it->first)) > 0){
vector<ll> res1 = it->second;
vector<ll> res2 = memo2[SS - (it->first)];
rep(i,res1.size()){
rep(j,res2.size()){
ll S = res1[i] | (res2[j]<<P1.size());
vector<int> res;
rep(i,40){
if((S>>i)&1) res.push_back(i+1);
}
ret[res] = 1;
}
}
}
}
FOR(it,ret){
rep(i,(it->first).size()){
if(i>0) cout << " ";
cout << (it->first)[i];
}
cout << endl;
}
return 0;
}
どらら