結果

問題 No.2161 Black Market
ユーザー hotman78hotman78
提出日時 2022-12-12 11:29:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 798 ms / 7,000 ms
コード長 1,992 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 244,072 KB
実行使用メモリ 9,276 KB
最終ジャッジ日時 2023-08-06 06:56:30
合計ジャッジ時間 8,664 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 518 ms
9,276 KB
testcase_21 AC 514 ms
9,256 KB
testcase_22 AC 110 ms
9,272 KB
testcase_23 AC 612 ms
9,084 KB
testcase_24 AC 798 ms
9,260 KB
testcase_25 AC 151 ms
9,256 KB
testcase_26 AC 675 ms
9,260 KB
testcase_27 AC 46 ms
8,068 KB
testcase_28 AC 48 ms
8,376 KB
testcase_29 AC 15 ms
4,784 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 228 ms
7,124 KB
testcase_32 AC 44 ms
8,072 KB
testcase_33 AC 29 ms
4,376 KB
testcase_34 AC 9 ms
4,380 KB
testcase_35 AC 11 ms
4,380 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 21 ms
5,028 KB
testcase_39 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using lint =long long;
#define rep(i,n) for(lint i=0;i<n;++i)
#define all(n) (n).begin(),(n).end()
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;

int main(){
    lint n,k,l,p;
    cin>>n>>k>>l>>p;
    vector<lint> a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    vector<vector<pair<lint,lint>>>s;
    vector<vector<pair<lint,lint>>>t;
    s.resize(n+1);
    t.resize(n+1);
    rep(i,1<<(n/2)){
        lint c=0,v=0;
        rep(j,n/2){
            if(i>>j&1){
                c+=a[j];
                v+=b[j];
            }
        }
        s[__builtin_popcountll(i)].emplace_back(c,v);
    }
        rep(i,1<<(n-n/2)){
        lint c=0,v=0;
        rep(j,n-n/2){
            if(i>>j&1){
                c+=a[j+n/2];
                v+=b[j+n/2];
            }
        }
        t[__builtin_popcountll(i)].emplace_back(c,v);
    }
    rep(i,n)sort(all(s[i]));
    rep(i,n)sort(all(t[i]));
    rep(i,n)reverse(all(t[i]));
    lint ans=0;
    rep(i,k+1){
        rep(j,k-i+1){
            lint now=0;
            pbds<pair<lint,lint>>r;
            for(auto [c,v]:t[j]){
                while(now<(int)s[i].size()&&s[i][now].first+c<=l){
                    r.insert(make_pair(s[i][now].second,now));
                    now++;
                }
                ans+=(int)r.size()-r.order_of_key(make_pair(p-v,-1LL));
            }
        }
    }
    cout<<ans<<endl;
}
0