結果
問題 | No.2161 Black Market |
ユーザー | 👑 AngrySadEight |
提出日時 | 2022-11-23 17:29:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 5,911 ms / 7,000 ms |
コード長 | 2,626 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 82,660 KB |
実行使用メモリ | 175,728 KB |
最終ジャッジ日時 | 2024-10-14 18:41:37 |
合計ジャッジ時間 | 30,142 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
56,448 KB |
testcase_01 | AC | 46 ms
56,320 KB |
testcase_02 | AC | 68 ms
70,784 KB |
testcase_03 | AC | 45 ms
56,448 KB |
testcase_04 | AC | 46 ms
56,576 KB |
testcase_05 | AC | 46 ms
56,448 KB |
testcase_06 | AC | 70 ms
72,716 KB |
testcase_07 | AC | 97 ms
78,808 KB |
testcase_08 | AC | 101 ms
78,788 KB |
testcase_09 | AC | 99 ms
78,772 KB |
testcase_10 | AC | 88 ms
79,188 KB |
testcase_11 | AC | 74 ms
74,112 KB |
testcase_12 | AC | 64 ms
68,480 KB |
testcase_13 | AC | 51 ms
62,528 KB |
testcase_14 | AC | 55 ms
63,744 KB |
testcase_15 | AC | 84 ms
78,844 KB |
testcase_16 | AC | 65 ms
69,760 KB |
testcase_17 | AC | 48 ms
56,832 KB |
testcase_18 | AC | 47 ms
56,448 KB |
testcase_19 | AC | 62 ms
67,712 KB |
testcase_20 | AC | 1,286 ms
112,468 KB |
testcase_21 | AC | 1,310 ms
112,420 KB |
testcase_22 | AC | 1,849 ms
121,984 KB |
testcase_23 | AC | 2,303 ms
121,844 KB |
testcase_24 | AC | 5,911 ms
175,288 KB |
testcase_25 | AC | 1,450 ms
164,864 KB |
testcase_26 | AC | 4,768 ms
175,728 KB |
testcase_27 | AC | 836 ms
171,488 KB |
testcase_28 | AC | 847 ms
164,284 KB |
testcase_29 | AC | 259 ms
94,868 KB |
testcase_30 | AC | 161 ms
80,768 KB |
testcase_31 | AC | 2,719 ms
153,828 KB |
testcase_32 | AC | 809 ms
164,564 KB |
testcase_33 | AC | 296 ms
84,960 KB |
testcase_34 | AC | 205 ms
96,788 KB |
testcase_35 | AC | 220 ms
93,784 KB |
testcase_36 | AC | 243 ms
87,352 KB |
testcase_37 | AC | 161 ms
81,024 KB |
testcase_38 | AC | 1,222 ms
110,976 KB |
testcase_39 | AC | 126 ms
80,792 KB |
ソースコード
from collections import defaultdict import bisect class BIT: def __init__(self, n): self.size = n self.list = [0] * (n + 1) def add(self, i, x): if i == 0: return while i <= self.size: self.list[i] += x i += (i & -i) def sum(self, i): if i == 0: return 0 ret = 0 while i > 0: ret += self.list[i] i -= (i & -i) return ret def MakeList(lst): ret = [[] for _ in range(len(lst) + 1)] for i in range(1 << (len(lst))): popcnt = 0 b = 0 a = 0 for j in range(len(lst)): if ((i >> j) & 1): popcnt += 1 b += lst[j][0] a += lst[j][1] ret[popcnt].append([b, a]) for i in range(len(lst) + 1): ret[i].sort() return ret def MakeUniqueA(lst): new_lst = [] for i in range(len(lst)): for j in range(len(lst[i])): new_lst.append(lst[i][j][1]) ret = list(set(new_lst)) ret.sort() return ret N, K, L, P = map(int, input().split()) former = [] latter = [] for i in range(N): a, b = map(int, input().split()) if i < N // 2: former.append([b, a]) else: latter.append([b, a]) former_lst = MakeList(former) latter_lst = MakeList(latter) former_a = MakeUniqueA(former_lst) latter_a = MakeUniqueA(latter_lst) #print(former_a) #print(latter_a) d_former = defaultdict(int) d_latter = defaultdict(int) for i in range(len(former_a)): d_former[former_a[i]] = i + 1 for i in range(len(latter_a)): d_latter[latter_a[i]] = i + 1 idx = [0 for _ in range(len(former_a))] for i in range(len(former_a)): if former_a[i] + latter_a[len(latter_a) - 1] <= L: idx[i] = len(latter_a) elif former_a[i] + latter_a[0] > L: idx[i] = 0 else: idx[i] = bisect.bisect_right(latter_a, L - former_a[i]) bit = BIT((1 << 18) + 1) ans = 0 for i in range(len(former_lst)): for j in range(len(latter_lst)): if i + j > K: continue now = len(latter_lst[j]) - 1 for k in range(len(former_lst[i])): while now >= 0: if former_lst[i][k][0] + latter_lst[j][now][0] >= P: bit.add(d_latter[latter_lst[j][now][1]], 1) now -= 1 else: break sm = bit.sum(idx[d_former[former_lst[i][k][1]] - 1]) ans += sm for k in range(now + 1, len(latter_lst[j])): bit.add(d_latter[latter_lst[j][k][1]], -1) print(ans)