結果
問題 | No.777 再帰的ケーキ |
ユーザー | tenten |
提出日時 | 2020-12-16 18:53:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,557 ms / 2,000 ms |
コード長 | 2,436 bytes |
コンパイル時間 | 2,129 ms |
コンパイル使用メモリ | 79,512 KB |
実行使用メモリ | 83,072 KB |
最終ジャッジ日時 | 2024-09-20 05:15:02 |
合計ジャッジ時間 | 15,183 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
49,848 KB |
testcase_01 | AC | 49 ms
50,452 KB |
testcase_02 | AC | 49 ms
50,308 KB |
testcase_03 | AC | 50 ms
50,180 KB |
testcase_04 | AC | 52 ms
50,396 KB |
testcase_05 | AC | 53 ms
50,484 KB |
testcase_06 | AC | 53 ms
50,056 KB |
testcase_07 | AC | 53 ms
50,024 KB |
testcase_08 | AC | 52 ms
50,024 KB |
testcase_09 | AC | 53 ms
50,216 KB |
testcase_10 | AC | 52 ms
50,448 KB |
testcase_11 | AC | 52 ms
50,024 KB |
testcase_12 | AC | 53 ms
50,436 KB |
testcase_13 | AC | 53 ms
52,024 KB |
testcase_14 | AC | 52 ms
50,168 KB |
testcase_15 | AC | 52 ms
50,220 KB |
testcase_16 | AC | 51 ms
50,012 KB |
testcase_17 | AC | 50 ms
50,244 KB |
testcase_18 | AC | 51 ms
50,500 KB |
testcase_19 | AC | 52 ms
50,144 KB |
testcase_20 | AC | 53 ms
50,120 KB |
testcase_21 | AC | 148 ms
53,736 KB |
testcase_22 | AC | 140 ms
53,640 KB |
testcase_23 | AC | 96 ms
51,564 KB |
testcase_24 | AC | 99 ms
51,548 KB |
testcase_25 | AC | 142 ms
53,500 KB |
testcase_26 | AC | 142 ms
53,360 KB |
testcase_27 | AC | 118 ms
53,076 KB |
testcase_28 | AC | 1,557 ms
83,072 KB |
testcase_29 | AC | 1,530 ms
82,276 KB |
testcase_30 | AC | 1,508 ms
80,296 KB |
testcase_31 | AC | 1,495 ms
80,676 KB |
testcase_32 | AC | 787 ms
80,920 KB |
testcase_33 | AC | 402 ms
59,828 KB |
testcase_34 | AC | 506 ms
61,988 KB |
testcase_35 | AC | 1,098 ms
75,576 KB |
testcase_36 | AC | 801 ms
82,872 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); Cake[] cakes = new Cake[n]; for (int i = 0; i < n; i++) { cakes[i] = new Cake(br.readLine()); } Arrays.sort(cakes); Cake.doCompress(); int size = 1; long max = 0; BinaryIndexedTree bit = new BinaryIndexedTree(Cake.size); for (Cake c : cakes) { long next = bit.getMax(c.getIdx() - 1) + c.cal; max = Math.max(max, next); bit.set(c.getIdx(), next); } System.out.println(max); } static class Cake implements Comparable<Cake> { static int size = 1; static TreeMap<Integer, Integer> compress = new TreeMap<>(); static void doCompress() { for (int x : compress.keySet()) { compress.put(x, size); size++; } } int width; int height; int cal; public Cake(int width, int height, int cal) { this.width = width; this.height = height; this.cal = cal; compress.put(height, 0); } public Cake(String line) { this(line.split(" ", 3)); } public Cake(String[] element) { this(Integer.parseInt(element[0]), Integer.parseInt(element[1]), Integer.parseInt(element[2])); } public int getIdx() { return compress.get(height); } public int compareTo(Cake another) { if (width == another.width) { return another.height - height; } else { return width - another.width; } } } } 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; } }