結果

問題 No.497 入れ子の箱
ユーザー htensaihtensai
提出日時 2020-01-08 13:08:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 178 ms / 5,000 ms
コード長 2,285 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 79,016 KB
実行使用メモリ 48,316 KB
最終ジャッジ日時 2024-05-02 12:43:17
合計ジャッジ時間 7,584 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
37,072 KB
testcase_01 AC 46 ms
37,340 KB
testcase_02 AC 46 ms
37,048 KB
testcase_03 AC 154 ms
48,316 KB
testcase_04 AC 152 ms
47,468 KB
testcase_05 AC 157 ms
47,460 KB
testcase_06 AC 146 ms
48,068 KB
testcase_07 AC 166 ms
48,108 KB
testcase_08 AC 165 ms
47,908 KB
testcase_09 AC 150 ms
48,060 KB
testcase_10 AC 157 ms
48,092 KB
testcase_11 AC 157 ms
48,000 KB
testcase_12 AC 170 ms
47,940 KB
testcase_13 AC 158 ms
47,840 KB
testcase_14 AC 152 ms
48,032 KB
testcase_15 AC 160 ms
47,840 KB
testcase_16 AC 158 ms
48,008 KB
testcase_17 AC 162 ms
47,864 KB
testcase_18 AC 158 ms
47,684 KB
testcase_19 AC 173 ms
48,024 KB
testcase_20 AC 154 ms
47,760 KB
testcase_21 AC 149 ms
47,716 KB
testcase_22 AC 159 ms
47,744 KB
testcase_23 AC 116 ms
46,912 KB
testcase_24 AC 126 ms
46,904 KB
testcase_25 AC 47 ms
37,120 KB
testcase_26 AC 47 ms
36,860 KB
testcase_27 AC 176 ms
48,100 KB
testcase_28 AC 178 ms
48,160 KB
testcase_29 AC 169 ms
47,864 KB
testcase_30 AC 134 ms
47,340 KB
testcase_31 AC 129 ms
47,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[][] 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 int[n][n + 1];
        boxes = new Box[n + 1];
        for (int i = 0; i < n; i++) {
            boxes[i] = new Box(br.readLine());
            Arrays.fill(dp[i], -1);
        }
        boxes[n] = new Box(new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE});
        Arrays.sort(boxes);
        System.out.println(dfw(n - 1, n));
    }
    
    static int dfw(int idx, int bidx) {
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][bidx] != -1) {
            return dp[idx][bidx];
        }
        dp[idx][bidx] = dfw(idx - 1, bidx);
        if (boxes[bidx].smaller(boxes[idx])) {
            dp[idx][bidx] = Math.max(dp[idx][bidx], dfw(idx - 1, idx) + 1);
        }
        return dp[idx][bidx];
    }
    
    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