結果
| 問題 | No.777 再帰的ケーキ | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-03-20 11:17:20 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 927 ms / 2,000 ms | 
| コード長 | 1,109 bytes | 
| コンパイル時間 | 359 ms | 
| コンパイル使用メモリ | 82,436 KB | 
| 実行使用メモリ | 266,524 KB | 
| 最終ジャッジ日時 | 2024-12-14 04:01:23 | 
| 合計ジャッジ時間 | 10,689 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 33 | 
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
A, B, C = zip(*zip(m, m, m))
class MaxBIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.data = [0] * self.size
    def get_max(self, i):
        s = 0
        while i:
            t = self.data[i]
            if s < t:
                s = t
            i -= i & -i
        return s
    def update(self, i, x):
        while i < self.size:
            if self.data[i] >= x:
                return
            self.data[i] = x
            i += i & -i
def compress(A):
    x_to_i = {x: i for i, x in enumerate(sorted(set(A)), 1)}
    return [x_to_i[x] for x in A]
A = compress(A)
B = compress(B)
A_to_BC = [[] for _ in range(N + 10)]
for a, b, c in zip(A, B, C):
    A_to_BC[a].append((b, c))
dp = MaxBIT(N)
for BC in A_to_BC:
    update = []
    for b, c in BC:
        update.append((b, dp.get_max(b - 1) + c))
    for b, x in update:
        dp.update(b, x)
print(dp.get_max(N))
            
            
            
        