結果
問題 | No.1826 Fruits Collecting |
ユーザー | chineristAC |
提出日時 | 2022-01-28 22:55:54 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 1,142 ms / 2,000 ms |
コード長 | 2,002 bytes |
コンパイル時間 | 304 ms |
コンパイル使用メモリ | 87,000 KB |
実行使用メモリ | 226,328 KB |
最終ジャッジ日時 | 2023-08-28 21:33:01 |
合計ジャッジ時間 | 27,816 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
79,696 KB |
testcase_01 | AC | 167 ms
82,108 KB |
testcase_02 | AC | 165 ms
81,952 KB |
testcase_03 | AC | 173 ms
82,864 KB |
testcase_04 | AC | 141 ms
79,420 KB |
testcase_05 | AC | 539 ms
135,816 KB |
testcase_06 | AC | 772 ms
153,796 KB |
testcase_07 | AC | 613 ms
146,808 KB |
testcase_08 | AC | 214 ms
87,216 KB |
testcase_09 | AC | 758 ms
163,616 KB |
testcase_10 | AC | 574 ms
140,748 KB |
testcase_11 | AC | 545 ms
145,428 KB |
testcase_12 | AC | 312 ms
103,336 KB |
testcase_13 | AC | 239 ms
91,856 KB |
testcase_14 | AC | 277 ms
98,456 KB |
testcase_15 | AC | 1,139 ms
226,100 KB |
testcase_16 | AC | 1,120 ms
225,864 KB |
testcase_17 | AC | 1,122 ms
226,040 KB |
testcase_18 | AC | 1,113 ms
225,816 KB |
testcase_19 | AC | 1,099 ms
225,848 KB |
testcase_20 | AC | 1,105 ms
226,036 KB |
testcase_21 | AC | 1,087 ms
225,672 KB |
testcase_22 | AC | 1,116 ms
225,692 KB |
testcase_23 | AC | 1,113 ms
226,220 KB |
testcase_24 | AC | 1,142 ms
226,328 KB |
testcase_25 | AC | 120 ms
74,544 KB |
testcase_26 | AC | 119 ms
74,596 KB |
testcase_27 | AC | 119 ms
74,512 KB |
testcase_28 | AC | 118 ms
74,784 KB |
testcase_29 | AC | 120 ms
74,720 KB |
testcase_30 | AC | 334 ms
111,860 KB |
testcase_31 | AC | 501 ms
135,472 KB |
testcase_32 | AC | 369 ms
115,228 KB |
testcase_33 | AC | 899 ms
184,792 KB |
testcase_34 | AC | 743 ms
154,828 KB |
testcase_35 | AC | 295 ms
99,236 KB |
testcase_36 | AC | 823 ms
178,452 KB |
testcase_37 | AC | 661 ms
160,920 KB |
testcase_38 | AC | 480 ms
133,628 KB |
testcase_39 | AC | 522 ms
147,292 KB |
testcase_40 | AC | 625 ms
169,500 KB |
testcase_41 | AC | 265 ms
102,580 KB |
testcase_42 | AC | 185 ms
83,848 KB |
testcase_43 | AC | 120 ms
74,588 KB |
testcase_44 | AC | 118 ms
74,136 KB |
testcase_45 | AC | 118 ms
74,508 KB |
ソースコード
class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): 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 self.size = n 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] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = self.segfunc(self.tree[k],x) while k > 1: k >>= 1 self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1]) def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num right = [] while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: right.append(self.tree[r-1]) l >>= 1 r >>= 1 for e in right[::-1]: res = self.segfunc(res,e) return res import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N = int(input()) item = [tuple(mi()) for i in range(N)] dic = {} for t,x,v in item: if (t,x) not in dic: dic[t,x] = 0 dic[t,x] += v item = [(t,x,dic[t,x]) for (t,x) in dic] N = len(item) item.sort(key=lambda x:x[0]-x[1]) val = set([x[0]+x[1] for x in item]+[0]) comp = {e:i for i,e in enumerate(sorted(val))} n = len(comp) dp = SegmentTree([-10**17]*n,max,-10**17) dp.update(comp[0],0) for t,x,v in item: if t-x < 0: continue tmp = dp.query(0,comp[t+x]+1) + v dp.update(comp[t+x],tmp) print(dp.query(0,n))