結果

問題 No.15 カタログショッピング
ユーザー どららどらら
提出日時 2017-02-26 01:06:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,415 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 170,144 KB
実行使用メモリ 14,376 KB
最終ジャッジ日時 2023-09-02 08:38:52
合計ジャッジ時間 2,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  ll SS;
  cin >> N >> SS;
  vector<ll> P(N);
  rep(i,N){
    cin >> P[i];
  }

  vector<ll> P1, P2;
  rep(i,N/2){
    P1.push_back(P[i]);
  }
  REP(i,N/2,N){
    P2.push_back(P[i]);
  }

  map<ll,vector<ll> > memo1, memo2;
  for(ll S=0; S<(1<<P1.size()); S++){
    ll sum = 0;
    rep(i,16){
      if((S>>i)&1) sum += P1[i];
    }
    memo1[sum].push_back(S);
  }
  for(ll S=0; S<(1<<P2.size()); S++){
    ll sum = 0;
    rep(i,16){
      if((S>>i)&1) sum += P2[i];
    }
    memo2[sum].push_back(S);
  }

  map<vector<int>,int> ret;
  FOR(it,memo1){
    if(memo2.count(SS - (it->first)) > 0){
      vector<ll> res1 = it->second;
      vector<ll> res2 = memo2[SS - (it->first)];
      rep(i,res1.size()){
        rep(j,res2.size()){
          ll S = res1[i] | (res2[j]<<P1.size()); 
          vector<int> res;
          rep(i,40){
            if((S>>i)&1) res.push_back(i+1);
          }
          ret[res] = 1;
        }
      }
    }
  }

  FOR(it,ret){
    rep(i,(it->first).size()){
      if(i>0) cout << " ";
      cout << (it->first)[i];
    }
    cout << endl;
  }

  
  return 0;
}

0