結果

問題 No.2161 Black Market
ユーザー hotman78hotman78
提出日時 2022-12-12 11:26:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,003 bytes
コンパイル時間 3,746 ms
コンパイル使用メモリ 237,980 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2024-04-24 03:05:15
合計ジャッジ時間 7,170 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 12 ms
5,376 KB
testcase_31 AC 229 ms
7,368 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 9 ms
5,376 KB
testcase_35 AC 12 ms
5,376 KB
testcase_36 AC 8 ms
5,376 KB
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 3 ms
5,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];
    array<vector<pair<lint,lint>>,17>s;
    array<vector<pair<lint,lint>>,17>t;
    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,17)sort(all(s[i]));
    rep(i,17)sort(all(t[i]));
    rep(i,17)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]){
                // cerr<<c<<" "<<v<<endl;
                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