結果
問題 | No.2161 Black Market |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-09-21 13:31:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,333 ms / 7,000 ms |
コード長 | 3,644 bytes |
コンパイル時間 | 352 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 276,340 KB |
最終ジャッジ日時 | 2024-07-07 07:13:58 |
合計ジャッジ時間 | 13,947 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
56,320 KB |
testcase_01 | AC | 46 ms
55,808 KB |
testcase_02 | AC | 89 ms
77,568 KB |
testcase_03 | AC | 46 ms
55,936 KB |
testcase_04 | AC | 46 ms
56,320 KB |
testcase_05 | AC | 46 ms
55,808 KB |
testcase_06 | AC | 70 ms
69,248 KB |
testcase_07 | AC | 85 ms
76,928 KB |
testcase_08 | AC | 96 ms
77,312 KB |
testcase_09 | AC | 95 ms
77,184 KB |
testcase_10 | AC | 100 ms
77,952 KB |
testcase_11 | AC | 93 ms
77,696 KB |
testcase_12 | AC | 88 ms
77,440 KB |
testcase_13 | AC | 49 ms
60,800 KB |
testcase_14 | AC | 62 ms
66,560 KB |
testcase_15 | AC | 100 ms
77,952 KB |
testcase_16 | AC | 79 ms
74,496 KB |
testcase_17 | AC | 47 ms
56,448 KB |
testcase_18 | AC | 46 ms
56,192 KB |
testcase_19 | AC | 72 ms
71,424 KB |
testcase_20 | AC | 404 ms
97,676 KB |
testcase_21 | AC | 409 ms
98,316 KB |
testcase_22 | AC | 490 ms
96,536 KB |
testcase_23 | AC | 471 ms
95,624 KB |
testcase_24 | AC | 1,333 ms
275,376 KB |
testcase_25 | AC | 974 ms
275,512 KB |
testcase_26 | AC | 1,245 ms
275,304 KB |
testcase_27 | AC | 896 ms
275,512 KB |
testcase_28 | AC | 1,059 ms
276,156 KB |
testcase_29 | AC | 311 ms
176,140 KB |
testcase_30 | AC | 153 ms
88,192 KB |
testcase_31 | AC | 887 ms
268,972 KB |
testcase_32 | AC | 909 ms
276,340 KB |
testcase_33 | AC | 218 ms
108,452 KB |
testcase_34 | AC | 214 ms
154,112 KB |
testcase_35 | AC | 232 ms
176,140 KB |
testcase_36 | AC | 182 ms
119,424 KB |
testcase_37 | AC | 134 ms
87,808 KB |
testcase_38 | AC | 401 ms
171,972 KB |
testcase_39 | AC | 115 ms
87,552 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline def segfunc(x, y): return min(x,y) ide_ele = float('inf') class SegTree: """ Segment Tree """ def __init__(self, init_val, segfunc, ide_ele): """ 初期化 init_val: 配列の初期値 """ n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = init_val[i] # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): """ k番目の値をxに更新 k: index(0-index) x: update value """ k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): """ [l, r)のsegfuncしたものを得る l: index(0-index) r: index(0-index) """ res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res N,K,L,P = map(int,input().split()) AB = [tuple(map(int,input().split())) for _ in range(N)] n = N//2 m = N-n X,Y = AB[:n],AB[n:] SX = defaultdict(lambda:[]) SY = defaultdict(lambda:[]) cost = [] value = [] for i in range(1<<n): t = 0 c = 0 v = 0 for j in range(n): if (i>>j)&1: t += 1 a,b = X[j] c += a v += b SX[c].append((t,v)) value.append(v) for i in range(1<<m): t = 0 c = 0 v = 0 for j in range(m): if (i>>j)&1: t += 1 a,b = Y[j] c += a v += b SY[c].append((t,v)) value.append(v) for k in SX.keys(): cost.append(k) for k in SY.keys(): cost.append(k) cost = sorted(list(set(cost))) value = sorted(list(set(value))) nc = len(cost) nv = len(value) cc = {x:i for i,x in enumerate(cost)} cv = {x:i for i,x in enumerate(value)} T = [SegTree([0]*(nv),lambda x,y:x+y,0) for _ in range(m+1)] TT = [[0]*nv for _ in range(m+1)] KX = list(SX.keys()) KY = list(SY.keys()) KX.sort(reverse=True) KY.sort() def cle(a,D): y = len(D)-1 x = 0 if D[x]>=a: return 0 if D[y]<a: return y+1 while y-x>1: mid = (y+x)//2 if D[mid]<a: x = mid else: y = mid return y add_flg = defaultdict(lambda:False) y_idx = 0 ans = 0 for kx in KX: while (y_idx<len(KY)): if KY[y_idx]+kx >L: break if add_flg[y_idx]: y_idx += 1 continue for t,v in SY[KY[y_idx]]: T[t].update(cv[v],TT[t][cv[v]]+1) TT[t][cv[v]] += 1 add_flg[y_idx] = True y_idx += 1 for xt,xv in SX[kx]: lv = cle(P-xv,value) if lv==nv: continue for i in range(0,min(max(0,K-xt+1),m+1)): ans += T[i].query(lv,nv) print(ans)