結果

問題 No.2161 Black Market
ユーザー apricityapricity
提出日時 2024-02-11 10:25:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 273 ms / 7,000 ms
コード長 4,738 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 157,696 KB
実行使用メモリ 76,036 KB
最終ジャッジ日時 2024-02-11 10:25:44
合計ジャッジ時間 5,613 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 110 ms
17,096 KB
testcase_21 AC 109 ms
17,096 KB
testcase_22 AC 148 ms
17,092 KB
testcase_23 AC 133 ms
17,092 KB
testcase_24 AC 273 ms
76,036 KB
testcase_25 AC 133 ms
41,220 KB
testcase_26 AC 239 ms
65,796 KB
testcase_27 AC 85 ms
28,932 KB
testcase_28 AC 89 ms
30,980 KB
testcase_29 AC 24 ms
10,756 KB
testcase_30 AC 9 ms
6,676 KB
testcase_31 AC 134 ms
32,076 KB
testcase_32 AC 81 ms
24,836 KB
testcase_33 AC 20 ms
7,364 KB
testcase_34 AC 15 ms
7,552 KB
testcase_35 AC 20 ms
8,708 KB
testcase_36 AC 18 ms
9,076 KB
testcase_37 AC 10 ms
6,676 KB
testcase_38 AC 70 ms
19,332 KB
testcase_39 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<utility>
#include<tuple>
#include<cstdint>
#include<cstdio>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<cctype>
#include<chrono>
#include<random>
#include<cassert>
#include<cstddef>
#include<iterator>
#include<string_view>
#include<type_traits>

#ifdef LOCAL
#  include "debug_print.hpp"
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<typename T> using PQ = priority_queue<T,vector<T>>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void yesno(bool flag) {cout << (flag?"Yes":"No") << "\n";}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &x : v) is >> x;
    return is;
}
void in() {}
template<typename T, class... U>
void in(T &t, U &...u) {
    cin >> t;
    in(u...);
}
void out() { cout << "\n"; }
template<typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}
void outr() {}
template<typename T, class... U, char sep = ' '>
void outr(const T &t, const U &...u) {
    cout << t;
    outr(u...);
}

#include "atcoder/segtree.hpp"
ll op(ll a, ll b) {return a+b;}
ll e() {return 0;}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; ll l,p; in(n,k,l,p);
    vector<ll> a(n),b(n);
    rep(i,n) in(a[i],b[i]);

    int half_n = n/2;
    int half_f = (1 << half_n);
    int half_s = (1 << (n-half_n));

    vector<ll> cost_fst(half_f), val_fst(half_f);
    vector<ll> cost_snd(half_s), val_snd(half_s);
    vector<ll> cost_bin, val_bin;
    rep(bit, half_f){
        rep(i,half_n){
            if((bit >> i) & 1) {
                cost_fst[bit] += a[i];
                val_fst[bit] += b[i];
            }
        }
    }
    rep(i,half_f) {
        cost_bin.emplace_back(cost_fst[i]);
        val_bin.emplace_back(val_fst[i]);
    }

    sort(ALL(cost_bin)); UNIQUE(cost_bin);
    sort(ALL(val_bin)); UNIQUE(val_bin);
    int sz_cost = cost_bin.size();
    int sz_val = val_bin.size();

    vector<tuple<ll,ll,int>> pair_f, pair_s;
    rep(i,half_f){
        pair_f.emplace_back(cost_fst[i], val_fst[i], __builtin_popcount(i));
    }
    rep(bit, half_s){
        FOR(i,half_n,n){
            if((bit >> (i-half_n)) & 1) {
                cost_snd[bit] += a[i];
                val_snd[bit] += b[i];
            }
        }
    }
    rep(i,half_s){
        pair_s.emplace_back(cost_snd[i], val_snd[i], __builtin_popcount(i));
    }
    sort(ALL(pair_f)); sort(RALL(pair_s));
    vector<atcoder::segtree<ll,op,e>> st(k+1,atcoder::segtree<ll,op,e>(sz_val));

    int pos = 0;
    ll ans = 0;

    rep(i,half_s){
        while(pos < half_f and get<0>(pair_f[pos]) + get<0>(pair_s[i]) <= l){
            if(get<2> (pair_f[pos]) > k) {
                pos++;
                continue;
            }
            int val_idx = lower_bound(ALL(val_bin), get<1>(pair_f[pos])) - val_bin.begin();
            st[get<2>(pair_f[pos])].set(val_idx, st[get<2>(pair_f[pos])].get(val_idx)+1);
            pos++;
        }
        ll val_min = p-get<1>(pair_s[i]);
        if(val_min > val_bin.back()) continue;
        ll num_max = k-get<2>(pair_s[i]);
        rep(j,num_max+1){
            int val_idx = lower_bound(ALL(val_bin), val_min) - val_bin.begin();
            ans += st[j].prod(val_idx, sz_val);
        }
    }
    out(ans);
}
0