結果

問題 No.15 カタログショッピング
ユーザー neckrawarmerneckrawarmer
提出日時 2021-10-08 15:17:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,536 bytes
コンパイル時間 4,996 ms
コンパイル使用メモリ 278,664 KB
実行使用メモリ 5,960 KB
最終ジャッジ日時 2023-09-30 09:18:02
合計ジャッジ時間 5,931 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
#endif
using ll = long long;
using ld = long double;
const ll INF = 1ll<<60;
const ld EPS = 1.0/1e9;
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define del(x) sort(all(x)); x.erase(unique(all(x)),x.end());

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n,k; cin >> n >> k;
  vector<ll>a(n/2);
  rep(i,0,n/2) cin >> a[i];
  vector<ll>b((n+1)/2);
  rep(i,0,(n+1)/2) cin >> b[i];
  vector<pair<ll,string>>x;
  rep(i,0,(1ll<<(n+1)/2)){
    ll sum=0; string ind;
    rep(j,0,(n+1)/2) if(i&(1ll<<j)){
      sum+=b[j]; ind+=char('0'+j+n/2+1);
    }
    x.emplace_back(sum,ind);
  }
  sort(all(x));
  vector<string>ans; string d; string e="0000000000000000000000000000"; 
  rep(i,0,(1ll<<n/2)){
    ll sum=0; string s; 
    rep(j,0,(n/2)) if(i&(1ll<<j)){
      sum+=a[j]; s+=char('0'+j+1);
    }
    auto p=lower_bound(all(x),make_pair(k-sum,d));
    auto q=upper_bound(all(x),make_pair(k-sum,e));
    if(sum==k){
      ans.push_back(s);
    }
    while((*p).first==(*q).first){
      if(p!=x.end() && (*p).first+sum==k){
         ans.push_back(s+(*p).second);
      }
      else break;
      p++;
    }
  }
  sort(all(ans));
  fore(c,ans){
    rep(i,0,c.size()){
      if(i) cout << " ";
      cout << c[i]-'0';
    }
    cout << endl;
  }
}
0