結果

問題 No.15 カタログショッピング
ユーザー kzyKTkzyKT
提出日時 2016-05-21 04:20:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,704 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 168,396 KB
実行使用メモリ 14,488 KB
最終ジャッジ日時 2023-07-28 20:49:29
合計ジャッジ時間 3,024 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,s;
  cin >> n >> s;
  ll a[n];
  rep(i,n) R a[i];
  map<ll,vector<vector<ll> > > m;
  int k=n/2;
  rep(t,1<<k) {
    vector<ll> v;
    ll sum=0;
    rep(i,k) {
      if(t&(1<<i)) {
        v.pb(i+1);
        sum+=a[i];
      }
    }
    m[sum].pb(v);
  }
  n-=k;
  vector<vector<ll> > ans;
  rep(t,1<<n) {
    ll sum=0;
    vector<ll> v;
    rep(i,n) {
      if(t&(1<<i)) {
        v.pb(k+i+1);
        sum+=a[k+i];
      }
    }
    vector<vector<ll> > w=m[s-sum];
    rep(i,w.size()) {
      vector<ll> x=w[i];
      rep(j,v.size()) x.pb(v[j]);
      ans.pb(x);
    }
  }
  sort(all(ans));
  rep(i,ans.size()) PR(ans[i],ans[i].size());
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
0