結果

問題 No.2370 He ate many cakes
ユーザー umezoumezo
提出日時 2023-07-04 00:39:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 211,580 KB
実行使用メモリ 8,232 KB
最終ジャッジ日時 2023-09-24 21:50:33
合計ジャッジ時間 3,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 88 ms
8,096 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 47 ms
7,188 KB
testcase_11 AC 88 ms
8,088 KB
testcase_12 AC 46 ms
7,192 KB
testcase_13 AC 87 ms
8,216 KB
testcase_14 AC 85 ms
8,112 KB
testcase_15 AC 85 ms
8,232 KB
testcase_16 AC 15 ms
4,376 KB
testcase_17 AC 88 ms
8,216 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,k;
  cin>>n>>k;
  
  if(n==1){
    int a;
    cin>>a;
    if(k==1) cout<<max(a,0)<<endl;
    else cout<<min(a,0)<<endl;
    return 0;
  }
  
  vector<ll> A(n/2),B(n-n/2);
  rep(i,n/2) cin>>A[i];
  rep(i,n-n/2) cin>>B[i];
  
  map<ll,ll> m1,m2;
  for(int bit=0;bit<(1<<n/2);bit++){
    ll tmp=0;
    rep(i,n/2){
      if(bit&(1<<i)) tmp+=A[i];
    }
    m1[tmp]++;
  }
  int cc=0;
  for(int bit=0;bit<(1<<(n-n/2));bit++){
    ll tmp=0;
    rep(i,n-n/2){
      if(bit&(1<<i)) tmp+=B[i];
    }
    m2[tmp]++;
  }
  
  vector<ll> C,D;
  for(auto [x,y]:m2){
    C.push_back(x);
    D.push_back(y);
  }
  C.push_back(1e18);
  D.push_back(0);
  int c=C.size();
  for(int i=c-2;i>=0;i--) D[i]+=D[i+1];

  auto f=[&](ll x){
    ll cnt=0;
    for(auto [p,q]:m1){
      auto l=lower_bound(ALL(C),x-p)-C.begin();
      cnt+=D[l]*q;
    }
    if(cnt>=k) return false;
    return true;
  };
    
  ll ok=30000000001,ng=-30000000001;
  while(ok-ng>1){
    ll mid=(ok+ng)/2;
    if(f(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok-1<<endl;
    
  return 0;
}
0