結果

問題 No.777 再帰的ケーキ
ユーザー 👑 rin204rin204
提出日時 2022-02-12 22:35:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,406 ms / 2,000 ms
コード長 1,828 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 215,740 KB
最終ジャッジ日時 2023-09-11 11:09:05
合計ジャッジ時間 13,636 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,216 KB
testcase_01 AC 73 ms
71,136 KB
testcase_02 AC 73 ms
71,276 KB
testcase_03 AC 72 ms
71,368 KB
testcase_04 AC 73 ms
71,148 KB
testcase_05 AC 73 ms
71,276 KB
testcase_06 AC 73 ms
71,424 KB
testcase_07 AC 72 ms
71,244 KB
testcase_08 AC 74 ms
71,332 KB
testcase_09 AC 74 ms
71,360 KB
testcase_10 AC 73 ms
71,188 KB
testcase_11 AC 72 ms
71,360 KB
testcase_12 AC 75 ms
71,272 KB
testcase_13 AC 74 ms
71,380 KB
testcase_14 AC 73 ms
71,304 KB
testcase_15 AC 72 ms
71,240 KB
testcase_16 AC 75 ms
71,120 KB
testcase_17 AC 73 ms
71,328 KB
testcase_18 AC 72 ms
71,132 KB
testcase_19 AC 72 ms
71,400 KB
testcase_20 AC 74 ms
71,372 KB
testcase_21 AC 143 ms
78,880 KB
testcase_22 AC 141 ms
78,556 KB
testcase_23 AC 105 ms
77,064 KB
testcase_24 AC 106 ms
76,812 KB
testcase_25 AC 142 ms
78,868 KB
testcase_26 AC 142 ms
78,448 KB
testcase_27 AC 108 ms
78,068 KB
testcase_28 AC 1,406 ms
215,096 KB
testcase_29 AC 1,380 ms
215,740 KB
testcase_30 AC 1,390 ms
190,080 KB
testcase_31 AC 1,391 ms
190,224 KB
testcase_32 AC 531 ms
186,256 KB
testcase_33 AC 239 ms
98,388 KB
testcase_34 AC 309 ms
109,292 KB
testcase_35 AC 1,163 ms
140,876 KB
testcase_36 AC 531 ms
186,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree():
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def f5(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = x
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
            
        lres = self.e
        rres = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                lres = self.ope(lres, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                rres = self.ope(self.data[r], rres)
            l >>= 1
            r >>= 1
        return self.ope(lres, rres)
            
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i]

n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
abc.sort(key = lambda x:(-x[0], x[1]))
se = {0} | {b for _, b, _ in abc}
dic = {b:i for i, b in enumerate(sorted(se))}
l = len(se)
seg = SegTree(l, 0, max)
for _, b, c in abc:
    b = dic[b]
    tmp = seg.query(b + 1, l) + c
    if tmp > seg.get(b):
        seg.update(b, tmp)
print(seg.query(0, l))

0