結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  neckrawarmer | 
| 提出日時 | 2021-10-08 15:17:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 43 ms / 5,000 ms | 
| コード長 | 1,536 bytes | 
| コンパイル時間 | 5,730 ms | 
| コンパイル使用メモリ | 269,220 KB | 
| 最終ジャッジ日時 | 2025-01-24 21:40:05 | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#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;
  }
}
            
            
            
        