結果

問題 No.497 入れ子の箱
ユーザー tentententen
提出日時 2020-12-24 16:41:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 265 ms / 5,000 ms
コード長 1,344 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 78,280 KB
実行使用メモリ 61,092 KB
最終ジャッジ日時 2023-10-21 15:44:35
合計ジャッジ時間 10,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
57,260 KB
testcase_01 AC 113 ms
57,360 KB
testcase_02 AC 114 ms
57,492 KB
testcase_03 AC 224 ms
61,092 KB
testcase_04 AC 226 ms
60,104 KB
testcase_05 AC 220 ms
60,308 KB
testcase_06 AC 244 ms
60,628 KB
testcase_07 AC 225 ms
60,560 KB
testcase_08 AC 231 ms
60,796 KB
testcase_09 AC 231 ms
60,532 KB
testcase_10 AC 212 ms
60,352 KB
testcase_11 AC 225 ms
60,296 KB
testcase_12 AC 218 ms
60,280 KB
testcase_13 AC 217 ms
59,980 KB
testcase_14 AC 226 ms
60,548 KB
testcase_15 AC 216 ms
60,200 KB
testcase_16 AC 219 ms
60,132 KB
testcase_17 AC 223 ms
60,448 KB
testcase_18 AC 216 ms
60,440 KB
testcase_19 AC 229 ms
60,368 KB
testcase_20 AC 222 ms
60,284 KB
testcase_21 AC 220 ms
58,656 KB
testcase_22 AC 221 ms
60,420 KB
testcase_23 AC 193 ms
60,184 KB
testcase_24 AC 207 ms
60,448 KB
testcase_25 AC 116 ms
57,412 KB
testcase_26 AC 115 ms
57,328 KB
testcase_27 AC 237 ms
60,352 KB
testcase_28 AC 265 ms
58,804 KB
testcase_29 AC 226 ms
60,180 KB
testcase_30 AC 222 ms
60,136 KB
testcase_31 AC 220 ms
60,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Box[] boxes = new Box[n];
        for (int i = 0; i < n; i++) {
            boxes[i] = new Box(sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(boxes);
        int[] counts = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (boxes[j].bigger(boxes[i])) {
                    counts[i] = Math.max(counts[i], counts[j] + 1);
                    max = Math.max(max, counts[i]);
                }
            }
        }
        System.out.println(max + 1);
    }
    
    static class Box implements Comparable<Box> {
        int[] arr = new int[3];
        
        public Box(int x, int y, int z) {
            arr[0] = x;
            arr[1] = y;
            arr[2] = z;
            Arrays.sort(arr);
        }
        
        public int compareTo(Box another) {
            return arr[0] - another.arr[0];
        }
        
        public boolean bigger(Box another) {
            for (int i = 0; i < 3; i++) {
                if (arr[i] >= another.arr[i]) {
                    return false;
                }
            }
            return true;
        }
    }
}
0