結果
問題 | No.15 カタログショッピング |
ユーザー |
|
提出日時 | 2014-11-17 17:15:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 5,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 1,219 ms |
コンパイル使用メモリ | 71,512 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2025-01-02 16:42:34 |
合計ジャッジ時間 | 2,402 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d%lld",&n,&s); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:11:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | for(int i=0;i<n;i++)scanf("%lld",&v[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <vector> #include <map> #include <algorithm> #include <cstdio> using namespace std; int main(){ int n; long long s; scanf("%d%lld",&n,&s); vector<long long>v(n); for(int i=0;i<n;i++)scanf("%lld",&v[i]); if(n==1){ if(v[0]==s)puts("1"); return 0; } int mid=n/2; multimap<long long,vector<int> >mm; for(int i=0;i<1<<mid;i++){ long long val=0; vector<int>lst; for(int j=0;j<mid;j++)if(i&(1<<j)){ val+=v[j]; lst.push_back(j+1); } auto it=mm.upper_bound(val); mm.insert(make_pair(val,lst)); } vector<vector<int> >result; for(int i=0;i<1<<(n-mid);i++){ long long val=0; vector<int>lst; for(int j=0;j<(n-mid);j++)if(i&(1<<j)){ val+=v[mid+j]; lst.push_back(mid+j+1); } auto it=mm.equal_range(s-val); for(;it.first!=it.second;++it.first){ vector<int>x=it.first->second; x.insert(x.end(),lst.begin(),lst.end()); result.push_back(x); } } sort(result.begin(),result.end()); for(auto &e:result){ for(int i=0;i<e.size();i++){ printf(i<e.size()-1?"%d ":"%d\n",e[i]); } } }