結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 01:46:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 5,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 1,055 ms |
| コンパイル使用メモリ | 95,816 KB |
| 実行使用メモリ | 13,184 KB |
| 最終ジャッジ日時 | 2024-07-20 06:17:39 |
| 合計ジャッジ時間 | 1,852 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int N,S,P[31];
map<int,vector<int> >mp;
main()
{
cin>>N>>S;
for(int i=0;i<N;i++)cin>>P[i];
int L=N/2,R=N-L;
for(int i=0;i<1<<R;i++)
{
int now=0;
for(int j=0;j<R;j++)if(i>>j&1)now+=P[L+j];
mp[now].push_back(i);
}
vector<vector<int> >ans;
for(int i=0;i<1<<L;i++)
{
int now=0;
for(int j=0;j<L;j++)if(i>>j&1)now+=P[j];
for(int x:mp[S-now])
{
vector<int>tmp;
for(int j=0;j<L;j++)if(i>>j&1)tmp.push_back(j+1);
for(int j=0;j<R;j++)if(x>>j&1)tmp.push_back(L+j+1);
ans.push_back(tmp);
}
}
sort(ans.begin(),ans.end());
for(vector<int>&now:ans)
{
for(int i=0;i<now.size();i++)cout<<now[i]<<(i+1==now.size()?"\n":" ");
}
}