結果
問題 | No.2161 Black Market |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-09-21 13:30:30 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,635 bytes |
コンパイル時間 | 1,475 ms |
コンパイル使用メモリ | 86,752 KB |
実行使用メモリ | 280,552 KB |
最終ジャッジ日時 | 2023-09-21 13:30:55 |
合計ジャッジ時間 | 15,917 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 104 ms
72,416 KB |
testcase_01 | AC | 105 ms
72,352 KB |
testcase_02 | AC | 145 ms
80,692 KB |
testcase_03 | AC | 103 ms
72,544 KB |
testcase_04 | AC | 105 ms
72,344 KB |
testcase_05 | AC | 103 ms
72,444 KB |
testcase_06 | AC | 120 ms
78,100 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 147 ms
80,748 KB |
testcase_12 | AC | 139 ms
80,764 KB |
testcase_13 | AC | 106 ms
75,716 KB |
testcase_14 | AC | 113 ms
77,256 KB |
testcase_15 | RE | - |
testcase_16 | AC | 129 ms
78,060 KB |
testcase_17 | AC | 103 ms
72,484 KB |
testcase_18 | AC | 103 ms
72,740 KB |
testcase_19 | AC | 125 ms
78,064 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 1,073 ms
280,160 KB |
testcase_26 | RE | - |
testcase_27 | AC | 979 ms
278,068 KB |
testcase_28 | AC | 977 ms
280,552 KB |
testcase_29 | AC | 370 ms
179,088 KB |
testcase_30 | RE | - |
testcase_31 | AC | 972 ms
266,244 KB |
testcase_32 | AC | 986 ms
278,068 KB |
testcase_33 | RE | - |
testcase_34 | AC | 275 ms
154,736 KB |
testcase_35 | AC | 273 ms
173,424 KB |
testcase_36 | AC | 234 ms
121,112 KB |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 165 ms
89,452 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,max(0,K-xt+1)): ans += T[i].query(lv,nv) print(ans)