結果

問題 No.2161 Black Market
ユーザー KudeKude
提出日時 2022-12-12 23:13:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 7,000 ms
コード長 2,667 bytes
コンパイル時間 3,204 ms
コンパイル使用メモリ 253,768 KB
実行使用メモリ 12,264 KB
最終ジャッジ日時 2023-08-06 17:51:47
合計ジャッジ時間 5,744 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 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 1 ms
4,384 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 31 ms
11,752 KB
testcase_21 AC 32 ms
11,756 KB
testcase_22 AC 34 ms
11,676 KB
testcase_23 AC 44 ms
11,756 KB
testcase_24 AC 119 ms
11,744 KB
testcase_25 AC 70 ms
12,264 KB
testcase_26 AC 109 ms
12,124 KB
testcase_27 AC 55 ms
9,240 KB
testcase_28 AC 55 ms
9,324 KB
testcase_29 AC 14 ms
5,092 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 53 ms
9,224 KB
testcase_32 AC 54 ms
9,276 KB
testcase_33 AC 8 ms
4,380 KB
testcase_34 AC 9 ms
4,384 KB
testcase_35 AC 14 ms
4,876 KB
testcase_36 AC 7 ms
4,384 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 20 ms
6,028 KB
testcase_39 AC 4 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, l, p;
  cin >> n >> k >> l >> p;
  vector<vector<pair<ll, ll>>> ps1{{{0, 0}}}, ps2{{{0, 0}}};
  rep(_, n) {
    int a, b;
    cin >> a >> b;
    int sz = ps1.size();
    ps1.emplace_back();
    rrep(i, sz) {
      for(auto [x, y]: ps1[i]) {
        ps1[i+1].emplace_back(x + a, y + b);
      }
    }
    swap(ps1, ps2);
  }
  int sz1 = ps1.size(), sz2 = ps2.size();
  value_compression<ll> vc;
  rep(i, sz1) for(auto [x, y]: ps1[i]) vc.emplace_back(y);
  vc.build();
  rep(i, sz1) for(auto& [_, y]: ps1[i]) y = vc(y);
  rep(i, sz1) sort(all(ps1[i]));
  rep(i, sz2) sort(rall(ps2[i]));
  vector<pair<ll, ll>> d;
  int included = 0;
  ll ans = 0;
  rrep(k2, sz2) {
    int k1 = min(sz1 - 1, k - k2) + 1;
    if (k1 <= 0) continue;
    while(included < k1) {
      int dsz = d.size();
      d.insert(d.end(), all(ps1[included]));
      included++;
      inplace_merge(d.begin(), d.begin() + dsz, d.end());
    }
    int dsz = d.size();
    int ptr = 0;
    int m = vc.size();
    fenwick_tree<int> ft(m);
    for(auto [x, y]: ps2[k2]) {
      while(ptr < dsz && d[ptr].first <= l - x) {
        auto [_, yi] = d[ptr++];
        ft.add(yi, 1);
      }
      ans += ft.sum(vc(p - y), m);
    }
  }
  cout << ans << '\n';
}
0