結果

問題 No.1826 Fruits Collecting
ユーザー ygd.ygd.
提出日時 2022-01-29 12:41:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,399 ms / 2,000 ms
コード長 2,775 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 85,768 KB
実行使用メモリ 268,016 KB
最終ジャッジ日時 2023-08-30 10:17:07
合計ジャッジ時間 32,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
75,752 KB
testcase_01 AC 121 ms
77,584 KB
testcase_02 AC 107 ms
77,812 KB
testcase_03 AC 114 ms
77,904 KB
testcase_04 AC 91 ms
75,944 KB
testcase_05 AC 581 ms
159,868 KB
testcase_06 AC 986 ms
189,476 KB
testcase_07 AC 670 ms
196,588 KB
testcase_08 AC 147 ms
83,084 KB
testcase_09 AC 935 ms
223,072 KB
testcase_10 AC 671 ms
165,424 KB
testcase_11 AC 586 ms
165,492 KB
testcase_12 AC 277 ms
113,252 KB
testcase_13 AC 180 ms
91,728 KB
testcase_14 AC 244 ms
104,220 KB
testcase_15 AC 1,399 ms
266,952 KB
testcase_16 AC 1,339 ms
267,316 KB
testcase_17 AC 1,301 ms
267,764 KB
testcase_18 AC 1,313 ms
267,652 KB
testcase_19 AC 1,304 ms
267,632 KB
testcase_20 AC 1,318 ms
268,016 KB
testcase_21 AC 1,315 ms
267,284 KB
testcase_22 AC 1,307 ms
267,276 KB
testcase_23 AC 1,312 ms
267,464 KB
testcase_24 AC 1,373 ms
267,192 KB
testcase_25 AC 73 ms
70,800 KB
testcase_26 AC 72 ms
71,052 KB
testcase_27 AC 72 ms
71,232 KB
testcase_28 AC 73 ms
71,148 KB
testcase_29 AC 73 ms
70,912 KB
testcase_30 AC 351 ms
129,700 KB
testcase_31 AC 608 ms
153,872 KB
testcase_32 AC 325 ms
110,216 KB
testcase_33 AC 966 ms
248,296 KB
testcase_34 AC 821 ms
191,048 KB
testcase_35 AC 248 ms
106,840 KB
testcase_36 AC 934 ms
219,892 KB
testcase_37 AC 711 ms
191,868 KB
testcase_38 AC 532 ms
171,452 KB
testcase_39 AC 356 ms
159,532 KB
testcase_40 AC 448 ms
191,480 KB
testcase_41 AC 172 ms
99,416 KB
testcase_42 AC 117 ms
78,500 KB
testcase_43 AC 73 ms
71,148 KB
testcase_44 AC 71 ms
71,304 KB
testcase_45 AC 71 ms
71,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


def compress(S):
    S = set(S); S = list(S)
    S.sort()
    dic_comp_ori = {}
    dic_ori_comp = {}
    for i,a in enumerate(S):
        dic_ori_comp[a] = i
        dic_comp_ori[i] = a
    return dic_comp_ori, dic_ori_comp 

def main():
    N = int(input()); INF = pow(10,18)
    Z = [(0,0,0)]; A = [0]; B = [0] #スタート地点
    for i in range(N):
        t,x,v = map(int,input().split())
        a = t+x
        b = t-x
        Z.append((a,b,v))
        A.append(a)
        B.append(b)
    Z.sort(key = lambda x: (x[0],x[1]))
    #print(Z)
    dica_comp_ori, dica_ori_comp = compress(A)
    dicb_comp_ori, dicb_ori_comp = compress(B)
    dp = SegmentTree([-INF]*(N+1), max, -INF)
    Flag = True
    for a,b,v in Z:
        if Flag:
            if v == 0:
                b0 = dicb_ori_comp[0]
                dp.update(b0,0) #スタート地点に来たので初期化
                Flag = False
            continue
        bi = dicb_ori_comp[b]
        nv = dp.sum(0,bi+1) + v
        #print(nv)
        dp.update(bi,nv)
    ans = dp.sum(0,N+1)
    print(ans)



if __name__ == '__main__':
    main()
0