結果

問題 No.777 再帰的ケーキ
ユーザー tentententen
提出日時 2020-12-16 18:34:59
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,819 bytes
コンパイル時間 2,750 ms
コンパイル使用メモリ 80,276 KB
実行使用メモリ 137,940 KB
最終ジャッジ日時 2023-10-20 09:45:18
合計ジャッジ時間 14,126 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,404 KB
testcase_01 AC 129 ms
57,212 KB
testcase_02 AC 132 ms
57,404 KB
testcase_03 AC 128 ms
57,472 KB
testcase_04 AC 127 ms
57,356 KB
testcase_05 AC 130 ms
57,428 KB
testcase_06 AC 132 ms
57,324 KB
testcase_07 AC 141 ms
57,604 KB
testcase_08 AC 139 ms
55,760 KB
testcase_09 AC 131 ms
57,364 KB
testcase_10 AC 119 ms
56,288 KB
testcase_11 AC 117 ms
56,220 KB
testcase_12 AC 131 ms
55,732 KB
testcase_13 AC 127 ms
57,396 KB
testcase_14 AC 130 ms
55,624 KB
testcase_15 AC 131 ms
57,532 KB
testcase_16 AC 128 ms
57,224 KB
testcase_17 AC 134 ms
57,508 KB
testcase_18 AC 132 ms
57,416 KB
testcase_19 AC 138 ms
57,528 KB
testcase_20 AC 144 ms
55,692 KB
testcase_21 AC 273 ms
60,804 KB
testcase_22 AC 267 ms
59,020 KB
testcase_23 AC 221 ms
60,472 KB
testcase_24 AC 221 ms
60,492 KB
testcase_25 AC 283 ms
61,068 KB
testcase_26 AC 284 ms
61,636 KB
testcase_27 AC 240 ms
60,772 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<Integer, TreeMap<Integer, Integer>> cakes = new TreeMap<>();
		TreeMap<Integer, Integer> compress = new TreeMap<>();
		for (int i = 0; i < n; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    int c = sc.nextInt();
		    if (!cakes.containsKey(a)) {
		        cakes.put(a, new TreeMap<>());
		    }
		    if (!cakes.get(a).containsKey(-b) || cakes.get(a).get(-b) < c) {
		        cakes.get(a).put(-b, c);
		        compress.put(b, 0);
		    }
		}
		int size = 1;
		for (int x : compress.keySet()) {
		    compress.put(x, size);
		    size++;
		}
		long max = 0;
		BinaryIndexedTree bit = new BinaryIndexedTree(size);
		for (TreeMap<Integer, Integer> one : cakes.values()) {
		    for (int x : one.keySet()) {
		        int idx = compress.get(-x);
		        long next = bit.getMax(idx - 1) + one.get(x);
		        max = Math.max(max, next);
		        bit.set(idx, next);
		    }
		}
		System.out.println(max);
	}
}

class BinaryIndexedTree {
    int size;
    long[] tree;
    
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new long[size];
    }
    
    public void set(int idx, long value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] = Math.max(tree[idx], value);
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public long getMax(int x) {
        int mask = 1;
        long ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans = Math.max(ans, tree[x]);
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}
0