結果

問題 No.497 入れ子の箱
ユーザー tentententen
提出日時 2021-12-06 11:53:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 2,784 bytes
コンパイル時間 2,684 ms
コンパイル使用メモリ 76,204 KB
実行使用メモリ 54,724 KB
最終ジャッジ日時 2023-09-21 15:08:05
合計ジャッジ時間 7,053 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,788 KB
testcase_01 AC 42 ms
49,684 KB
testcase_02 AC 42 ms
49,700 KB
testcase_03 AC 75 ms
51,840 KB
testcase_04 AC 90 ms
53,312 KB
testcase_05 AC 85 ms
53,656 KB
testcase_06 AC 104 ms
53,520 KB
testcase_07 AC 91 ms
52,512 KB
testcase_08 AC 104 ms
52,740 KB
testcase_09 AC 102 ms
52,784 KB
testcase_10 AC 85 ms
52,024 KB
testcase_11 AC 90 ms
52,752 KB
testcase_12 AC 113 ms
53,376 KB
testcase_13 AC 111 ms
53,380 KB
testcase_14 AC 108 ms
53,636 KB
testcase_15 AC 123 ms
53,412 KB
testcase_16 AC 124 ms
53,364 KB
testcase_17 AC 115 ms
53,900 KB
testcase_18 AC 94 ms
52,860 KB
testcase_19 AC 91 ms
54,724 KB
testcase_20 AC 97 ms
52,500 KB
testcase_21 AC 95 ms
53,104 KB
testcase_22 AC 103 ms
52,968 KB
testcase_23 AC 100 ms
53,204 KB
testcase_24 AC 141 ms
53,780 KB
testcase_25 AC 45 ms
49,756 KB
testcase_26 AC 42 ms
49,876 KB
testcase_27 AC 92 ms
53,512 KB
testcase_28 AC 96 ms
52,992 KB
testcase_29 AC 122 ms
52,556 KB
testcase_30 AC 122 ms
53,424 KB
testcase_31 AC 138 ms
53,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayList<ArrayList<Box>> boxes = new ArrayList<>();
        boxes.add(new ArrayList<>());
        boxes.get(0).add(new Box(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));
        Box[] tmp = new Box[n];
        for (int i = 0; i < n; i++) {
            tmp[i] = new Box(sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(tmp);
        for (Box b : tmp) {
            for (int j = boxes.size() - 1; j >= 0; j--) {
                boolean ng = true;
                for (Box x : boxes.get(j)) {
                    if (x.isSmaller(b)) {
                        ng = false;
                        break;
                    }
                }
                if (!ng) {
                    if (j == boxes.size() - 1) {
                        boxes.add(new ArrayList<>());
                    }
                    boxes.get(j + 1).add(b);
                    break;
                }
            }
        }
        System.out.println(boxes.size() - 1);
    }
    
    static class Box implements Comparable<Box> {
        int big;
        int middle;
        int small;
        
        public Box(int[] arr) {
            Arrays.sort(arr);
            small = arr[0];
            middle = arr[1];
            big = arr[2];
        }
        
        public Box(int a, int b, int c) {
            this(new int[]{a, b, c});
        }
        
        public int compareTo(Box another) {
            if (big == another.big) {
                if (middle == another.middle) {
                    return another.small - small;
                } else {
                    return another.middle - middle;
                }
            } else {
                return another.big - big;
            }
        }
        
        public boolean isSmaller(Box another) {
            return big > another.big && middle > another.middle && small > another.small;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0