結果
問題 | No.2161 Black Market |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-09-21 13:30:30 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,635 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 278,008 KB |
最終ジャッジ日時 | 2024-07-07 07:13:42 |
合計ジャッジ時間 | 11,102 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,320 KB |
testcase_01 | AC | 38 ms
56,064 KB |
testcase_02 | AC | 72 ms
77,440 KB |
testcase_03 | AC | 38 ms
56,448 KB |
testcase_04 | AC | 43 ms
56,192 KB |
testcase_05 | AC | 44 ms
56,320 KB |
testcase_06 | AC | 59 ms
69,504 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 80 ms
77,824 KB |
testcase_12 | AC | 75 ms
77,568 KB |
testcase_13 | AC | 45 ms
60,800 KB |
testcase_14 | AC | 53 ms
66,304 KB |
testcase_15 | RE | - |
testcase_16 | AC | 62 ms
74,752 KB |
testcase_17 | AC | 39 ms
56,704 KB |
testcase_18 | AC | 42 ms
56,064 KB |
testcase_19 | AC | 62 ms
71,552 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 887 ms
275,644 KB |
testcase_26 | RE | - |
testcase_27 | AC | 836 ms
275,256 KB |
testcase_28 | AC | 819 ms
278,008 KB |
testcase_29 | AC | 275 ms
176,280 KB |
testcase_30 | RE | - |
testcase_31 | AC | 809 ms
268,996 KB |
testcase_32 | AC | 817 ms
276,212 KB |
testcase_33 | RE | - |
testcase_34 | AC | 190 ms
154,164 KB |
testcase_35 | AC | 199 ms
176,280 KB |
testcase_36 | AC | 158 ms
119,296 KB |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 97 ms
87,864 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)