結果
問題 | No.2161 Black Market |
ユーザー | 👑 AngrySadEight |
提出日時 | 2022-11-23 14:56:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,610 ms / 7,000 ms |
コード長 | 4,052 bytes |
コンパイル時間 | 1,426 ms |
コンパイル使用メモリ | 109,356 KB |
実行使用メモリ | 23,824 KB |
最終ジャッジ日時 | 2024-10-14 18:40:11 |
合計ジャッジ時間 | 8,890 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,820 KB |
testcase_01 | AC | 4 ms
6,820 KB |
testcase_02 | AC | 4 ms
6,820 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | AC | 4 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,820 KB |
testcase_07 | AC | 4 ms
6,820 KB |
testcase_08 | AC | 4 ms
6,816 KB |
testcase_09 | AC | 5 ms
6,820 KB |
testcase_10 | AC | 4 ms
6,820 KB |
testcase_11 | AC | 4 ms
6,816 KB |
testcase_12 | AC | 4 ms
6,820 KB |
testcase_13 | AC | 3 ms
6,816 KB |
testcase_14 | AC | 3 ms
6,816 KB |
testcase_15 | AC | 4 ms
6,820 KB |
testcase_16 | AC | 4 ms
6,820 KB |
testcase_17 | AC | 4 ms
6,816 KB |
testcase_18 | AC | 3 ms
6,816 KB |
testcase_19 | AC | 4 ms
6,820 KB |
testcase_20 | AC | 289 ms
13,220 KB |
testcase_21 | AC | 281 ms
13,220 KB |
testcase_22 | AC | 277 ms
13,348 KB |
testcase_23 | AC | 292 ms
13,220 KB |
testcase_24 | AC | 1,610 ms
23,820 KB |
testcase_25 | AC | 364 ms
23,820 KB |
testcase_26 | AC | 1,480 ms
23,824 KB |
testcase_27 | AC | 144 ms
23,820 KB |
testcase_28 | AC | 142 ms
23,824 KB |
testcase_29 | AC | 35 ms
9,984 KB |
testcase_30 | AC | 23 ms
6,816 KB |
testcase_31 | AC | 758 ms
18,740 KB |
testcase_32 | AC | 137 ms
23,820 KB |
testcase_33 | AC | 52 ms
7,040 KB |
testcase_34 | AC | 25 ms
8,832 KB |
testcase_35 | AC | 30 ms
9,984 KB |
testcase_36 | AC | 43 ms
7,552 KB |
testcase_37 | AC | 25 ms
6,816 KB |
testcase_38 | AC | 320 ms
12,072 KB |
testcase_39 | AC | 14 ms
6,820 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> typedef long long ll; using namespace std; using pll = pair<ll,ll>; struct BIT{ //Binary Indexed Tree. ll N; vector<ll> vec; BIT(ll N_): N(N_), vec(N + 1){ for (ll i = 0; i < N + 1; i++){ vec[i] = 0; } } void add(ll p, ll x){ if (p == 0){ return; } for (ll i = p; i <= N; i += (i & -i)){ vec[i] += x; } } ll sum(ll p){ if (p == 0){ return 0; } ll sum = 0; for (ll i = p; i > 0; i -= (i & -i)){ sum += vec[i]; } return sum; } }; vector<vector<pll>> MakeVec(vector<pll> &vec){ ll len = vec.size(); vector<vector<pll>> ret(len + 1, vector<pll>(0)); for (ll i = 0; i < (1 << len); i++){ ll popcnt = 0; ll b = 0; ll a = 0; for (ll j = 0; j < len; j++){ if ((i >> j) & 1){ popcnt++; b += vec[j].first; a += vec[j].second; } } ret[popcnt].push_back(pll(b, a)); } for (ll i = 0; i <= len; i++){ sort(ret[i].begin(), ret[i].end()); } return ret; } vector<ll> MakeUniqueA(vector<vector<pll>> &vec){ vector<ll> ret(0); for (ll i = 0; i < vec.size(); i++){ for (ll j = 0; j < vec[i].size(); j++){ ret.push_back(vec[i][j].second); } } sort(ret.begin(), ret.end()); ret.erase(unique(ret.begin(), ret.end()), ret.end()); return ret; } int main(){ ll N, K, L, P; cin >> N >> K >> L >> P; vector<ll> A(N); vector<ll> B(N); for (ll i = 0; i < N; i++){ cin >> A[i] >> B[i]; } vector<pll> former(0); vector<pll> latter(0); for (ll i = 0; i < N / 2; i++) former.push_back(pll(B[i], A[i])); for (ll i = N / 2; i < N; i++) latter.push_back(pll(B[i], A[i])); vector<vector<pll>> former_vec = MakeVec(former); vector<vector<pll>> latter_vec = MakeVec(latter); vector<ll> former_a = MakeUniqueA(former_vec); vector<ll> latter_a = MakeUniqueA(latter_vec); //formerのほうを全探索する方針を取ることにする //そうすると,BITにはlatter_bの値(を座標圧縮した値)を追加することにしよう. unordered_map<ll, ll> mp_latter; for (ll i = 0; i < latter_a.size(); i++){ mp_latter[latter_a[i]] = i + 1; } unordered_map<ll, ll> mp_former; for (ll i = 0; i < former_a.size(); i++){ mp_former[former_a[i]] = i + 1; } vector<ll> idx(former_a.size()); for (ll i = 0; i < former_a.size(); i++){ if (former_a[i] + latter_a[latter_a.size() - 1] <= L){ idx[i] = latter_a.size(); } else if (former_a[i] + latter_a[0] > L){ idx[i] = 0; } else{ auto itr = upper_bound(latter_a.begin(), latter_a.end(), L - former_a[i]); idx[i] = itr - latter_a.begin(); } } BIT bit((1 << 18) + 1); ll ans = 0; for (ll i = 0; i < former_vec.size(); i++){ for (ll j = 0; j < latter_vec.size(); j++){ if (i + j > K){ continue; } ll now = latter_vec[j].size() - 1; for (ll k = 0; k < former_vec[i].size(); k++){ while(now >= 0){ if (former_vec[i][k].first + latter_vec[j][now].first >= P){ bit.add(mp_latter[latter_vec[j][now].second], 1); now--; } else{ break; } } ll sm = bit.sum(idx[mp_former[former_vec[i][k].second] - 1]); ans += sm; } for (ll k = now + 1; k < latter_vec[j].size(); k++){ bit.add(mp_latter[latter_vec[j][k].second], -1); } } } cout << ans << endl; return 0; }