結果
問題 | No.2161 Black Market |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-09-21 13:31:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,687 ms / 7,000 ms |
コード長 | 3,644 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 86,952 KB |
実行使用メモリ | 279,440 KB |
最終ジャッジ日時 | 2023-09-21 13:31:43 |
合計ジャッジ時間 | 18,731 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
72,464 KB |
testcase_01 | AC | 110 ms
72,620 KB |
testcase_02 | AC | 146 ms
80,476 KB |
testcase_03 | AC | 107 ms
72,428 KB |
testcase_04 | AC | 106 ms
72,760 KB |
testcase_05 | AC | 108 ms
72,604 KB |
testcase_06 | AC | 126 ms
78,140 KB |
testcase_07 | AC | 140 ms
79,952 KB |
testcase_08 | AC | 153 ms
80,156 KB |
testcase_09 | AC | 152 ms
80,616 KB |
testcase_10 | AC | 162 ms
80,844 KB |
testcase_11 | AC | 149 ms
80,476 KB |
testcase_12 | AC | 145 ms
80,872 KB |
testcase_13 | AC | 113 ms
75,912 KB |
testcase_14 | AC | 118 ms
77,436 KB |
testcase_15 | AC | 151 ms
80,668 KB |
testcase_16 | AC | 134 ms
78,124 KB |
testcase_17 | AC | 108 ms
72,504 KB |
testcase_18 | AC | 110 ms
72,464 KB |
testcase_19 | AC | 131 ms
78,012 KB |
testcase_20 | AC | 606 ms
103,052 KB |
testcase_21 | AC | 570 ms
103,344 KB |
testcase_22 | AC | 680 ms
100,684 KB |
testcase_23 | AC | 642 ms
98,260 KB |
testcase_24 | AC | 1,687 ms
276,728 KB |
testcase_25 | AC | 1,215 ms
279,440 KB |
testcase_26 | AC | 1,562 ms
277,576 KB |
testcase_27 | AC | 1,099 ms
278,236 KB |
testcase_28 | AC | 1,092 ms
279,400 KB |
testcase_29 | AC | 410 ms
178,980 KB |
testcase_30 | AC | 219 ms
89,880 KB |
testcase_31 | AC | 1,107 ms
266,176 KB |
testcase_32 | AC | 1,093 ms
278,132 KB |
testcase_33 | AC | 319 ms
111,020 KB |
testcase_34 | AC | 290 ms
154,708 KB |
testcase_35 | AC | 286 ms
173,264 KB |
testcase_36 | AC | 252 ms
120,856 KB |
testcase_37 | AC | 202 ms
89,912 KB |
testcase_38 | AC | 493 ms
183,100 KB |
testcase_39 | AC | 182 ms
89,776 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)