結果

問題 No.15 カタログショッピング
ユーザー imgry22imgry22
提出日時 2014-12-15 19:55:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 1,962 bytes
コンパイル時間 2,587 ms
コンパイル使用メモリ 160,984 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-02 14:53:21
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;

#define rrep(i, m, n) for(int i=m; i<n;  i++)
#define erep(i, n)    for(int i=1; i<=n; i++)
#define  rep(i, n)    for(int i=0; i<n;  i++)
#define rrev(i, m, n) for(int i=n-1; i>=m; i--)
#define erev(i, n)    for(int i=n; i>=1; i--)
#define  rev(i, n)    for(int i=n-1; i>=0; i--)
#define EACH(v)       (v).begin(), (v).end()
#define CNT(a, n, x)  (upper_bound(a, a+n, x)-lower_bound(a, a+n, x))
#define minup(m, x)   (m=min(m, x))
#define maxup(m, x)   (m=max(m, x))
#define mp            make_pair
#define pb            push_back

#define INF 10000000000000000
#define MOD 1000000009
#define EPS 1E-9

#define MAX_N 31

typedef vector<long long> vl;
typedef vector<pair<long long, long long> > vll;

int n;
ll s;
int p[MAX_N];

int main()
{
  cin >> n >> s;
  rep(i, n) cin >> p[i];

  int n1 = n/2;
  int n2 = n - n1;
  vll lsum(1<<(n/2));
  vll rsum(1<<(n/2+1));
  vll::iterator it;
  vl  res;

  rep(i, 1<<n1){
    ll sum = 0;
    rep(j, n1) if(i & 1 << (n1-j-1)) sum += p[j];
    lsum.pb(mp(sum, i));
  }

  rep(i, 1<<n2){
    ll sum = 0;
    rep(j, n2) if(i & 1 << (n2-j-1)) sum += p[n1 + j];
    rsum.pb(mp(sum, i));
  }

  sort(EACH(lsum));  lsum.erase(unique(EACH(lsum)), lsum.end());
  sort(EACH(rsum));  rsum.erase(unique(EACH(rsum)), rsum.end());

  rep(i, lsum.size()){
    vll::iterator st = lower_bound(EACH(rsum),mp(s-lsum[i].first,0LL));
    vll::iterator ed = lower_bound(EACH(rsum),mp(s-lsum[i].first+1,0LL));
    for(it=st; it!=ed; it++) res.pb(lsum[i].second*(1<<n2) + it->second);
  }

  sort(EACH(res));
  res.erase(unique(EACH(res)), res.end());

  rev(i, res.size()){
    rev(j, n) if(res[i] & 1LL << j) cout << n - j << " ";
    cout << endl;
  }

  return 0;
}
0