結果

問題 No.497 入れ子の箱
ユーザー htensaihtensai
提出日時 2020-01-08 12:55:43
言語 Java19
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,378 bytes
コンパイル時間 4,928 ms
コンパイル使用メモリ 74,508 KB
実行使用メモリ 59,572 KB
最終ジャッジ日時 2023-08-15 00:28:40
合計ジャッジ時間 9,542 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,096 KB
testcase_01 AC 44 ms
49,524 KB
testcase_02 AC 45 ms
49,896 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static HashMap<Box, Integer>[] dp;
    static Box[] boxes;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        dp = new HashMap[n];
        boxes = new Box[n];
        for (int i = 0; i < n; i++) {
            boxes[i] = new Box(br.readLine());
            dp[i] = new HashMap<Box, Integer>();
        }
        Arrays.sort(boxes);
        System.out.println(dfw(n - 1, new Box(new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE})));
    }
    
    static int dfw(int idx, Box box) {
        if (idx < 0) {
            return 0;
        }
        if (dp[idx].containsKey(box)) {
            return dp[idx].get(box);
        }
        int ans = dfw(idx - 1, box);
        if (box.smaller(boxes[idx])) {
            int tmp = dfw(idx - 1, boxes[idx]) + 1;
            if (ans < tmp) {
                ans = tmp;
                box = boxes[idx];
            }
        }
        dp[idx].put(box, ans);
        return ans;
    }
    
    static class Box implements Comparable<Box> {
        int[] arr = new int[3];
        
        public Box(int[] arr) {
            this.arr = arr;
            Arrays.sort(arr);
        }
        
        public Box(String line) {
            String[] lines = line.split(" ", 3);
            for (int i = 0; i < 3; i++) {
                arr[i] = Integer.parseInt(lines[i]);
            }
            Arrays.sort(arr);
        }
        
        public int compareTo(Box another) {
            for (int i = 0; i <= 2; i++) {
                if (arr[i] != another.arr[i]) {
                    return arr[i] - another.arr[i];
                }
            }
            return 0;
        }
        
        public boolean equals(Object o) {
            Box another = (Box)o;
            for (int i = 0; i < 3; i++) {
                if (arr[i] != another.arr[i]) {
                    return false;
                }
            }
            return true;
        }
        
        public boolean smaller(Box another) {
            for (int i = 0; i < 3; i++) {
                if (arr[i] <= another.arr[i]) {
                    return false;
                }
            }
            return true;
        }
    }
}
0