結果

問題 No.15 カタログショッピング
ユーザー SakaTakuSakaTaku
提出日時 2020-09-24 01:56:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,395 bytes
コンパイル時間 4,106 ms
コンパイル使用メモリ 184,036 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 13:17:01
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
   int n,s;cin>>n>>s;
   vector<int>p(n);
   rep(i,n)cin>>p[i];
   vector<P>A,B;
   A.push_back({0,0});
   B.push_back({0,0});
   for (int i = 0; i < n/2; i++){
      int size=A.size();
      for (int j = 0; j < size; j++){
         A.push_back({A[j].first+p[i],A[j].second+(1<<i)});
      }
   }
   for (int i = n/2; i < n; i++){
      int size=B.size();
      for (int j = 0; j < size; j++){
         B.push_back({B[j].first+p[i],B[j].second+(1<<i)});
      }
   }
   sort(A.begin(),A.end());
   sort(B.begin(),B.end());
   vector<int> ans;
   for (int i = 0; i < A.size(); i++){
      vector<P>::iterator l=lower_bound(B.begin(),B.end(),make_pair(s-A[i].first,0));
      vector<P>::iterator r=lower_bound(B.begin(),B.end(),make_pair(s-A[i].first+1,0));
      for (; l < r; l++){
         ans.push_back(A[i].second+(*l).second);
      }
   }
   vector<vector<int>> res;
   rep(i,ans.size()){
      vector<int> v;
      for (int j = 0; j < p.size(); j++){
         if((ans[i]>>j)&1)v.push_back(j+1);
      }
      res.push_back(v);
   }
   sort(res.begin(),res.end());
   for (int i = 0; i < res.size(); i++){
      cout<<res[i][0];
      for (int j = 1; j < res[i].size(); j++){
         cout<<" "<<res[i][j];
      }
      cout<<endl;
   }
}
0