結果
問題 |
No.15 カタログショッピング
|
ユーザー |
![]() |
提出日時 | 2017-07-15 11:23:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,911 bytes |
コンパイル時間 | 1,169 ms |
コンパイル使用メモリ | 107,716 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-10-08 02:09:10 |
合計ジャッジ時間 | 2,027 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 10 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main() { int n; cin>>n; ll s; cin>>s; ll p[n]; FOR(i,0,n) { scanf("%lld", p+i); } map<ll, vector<int> > S; // 合計金額, 集合 // 半分全列挙 int n2 = n / 2; FOR(i,0,1<<n2) { ll sum = 0; FOR(j,0,n2) { if((i>>j)&1) { sum += p[j]; } } S[sum].push_back(i); } // 残り半分で作れるやつ vector<vector<int> > ans(50, vector<int>(1, 0)); int cnt = 0; FOR(i,0,1<<(n-n2)) { int sum = 0; FOR(j,0,n-n2) { if((i>>j)&1) { sum += p[j+n2]; } } if(S.count(s-sum)>0) { for(int x : S[s-sum]) { FOR(j,0,n2) { if((x>>j)&1) { //cout << j + 1 << " "; ans[cnt].push_back(j+1); } } FOR(j,0,n-n2) { if((i>>j)&1) { //cout << j + n2 + 1 << " "; ans[cnt].push_back(j+n2+1); } } //cout << endl; while(ans[cnt].size()<n+1) { ans[cnt].push_back(0); } cnt++; } } } int sz = cnt; FOR(i,0,sz) { FOR(j,0,ans[i].size()) { cout<<ans[i][j]; } cout<<endl; } // 答えを昇順に並び替える FOR(k,0,n+1) { FOR(i,0,sz-1) { for(int j = sz-1; j > i; j--) { if(ans[j][k] < ans[j-1][k] && ans[j][k-1] == ans[j-1][k-1] ) { FOR(w,0,n+1) { swap(ans[j][w], ans[j-1][w]); } } } } } FOR(i,0,sz) { FOR(j,0,n+1) { if(ans[i][j]!=0) cout << ans[i][j] << " "; } cout << endl; } return 0; }