結果

問題 No.497 入れ子の箱
ユーザー KilisameKilisame
提出日時 2017-04-28 16:33:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,031 bytes
コンパイル時間 4,055 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 61,844 KB
最終ジャッジ日時 2023-10-11 18:56:47
合計ジャッジ時間 12,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,640 KB
testcase_01 AC 120 ms
55,396 KB
testcase_02 AC 119 ms
55,424 KB
testcase_03 AC 228 ms
59,884 KB
testcase_04 AC 238 ms
59,240 KB
testcase_05 AC 239 ms
59,312 KB
testcase_06 AC 235 ms
59,432 KB
testcase_07 AC 232 ms
59,740 KB
testcase_08 AC 235 ms
59,656 KB
testcase_09 AC 236 ms
59,572 KB
testcase_10 AC 237 ms
59,504 KB
testcase_11 AC 234 ms
57,448 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 181 ms
59,048 KB
testcase_24 AC 182 ms
58,768 KB
testcase_25 AC 117 ms
55,660 KB
testcase_26 AC 117 ms
55,948 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 184 ms
58,784 KB
testcase_31 AC 207 ms
59,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class NestedBox {

    private static int n;

    private static long[][] boxes;

    private static boolean[] checked;

    private static int max;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = Integer.parseInt(sc.next());
        boxes = new long[n][3];
        checked = new boolean[n];
        for (int i = 0; i < n; i++) {
            boxes[i][0] = Long.parseLong(sc.next());
            boxes[i][1] = Long.parseLong(sc.next());
            boxes[i][2] = Long.parseLong(sc.next());
            Arrays.sort(boxes[i]);
        }
        sc.close();
        Arrays.sort(boxes, new Comparator<long[]>() {
            @Override
            public int compare(long[] o1, long[] o2) {
                if (o1[0] < o2[0]) {
                    return -1;
                } else if (o1[0] > o2[0]) {
                    return 1;
                }
                if (o1[1] < o2[1]) {
                    return -1;
                } else if (o1[1] > o2[1]) {
                    return 1;
                }
                if (o1[2] < o2[2]) {
                    return -1;
                } else if (o1[2] > o2[2]) {
                    return 1;
                }
                return 0;
            }
        });
        max = 1;
        nest(0, 1);
        System.out.println(max);
    }

    private static void nest(int index, int count) {
        if (checked[index]) {
            return;
        }
        for (int i = index + 1; i < n; i++) {
            if (isIn(index, i)) {
                nest(i, count + 1);
            }
        }
        if (count > max) {
            max = count;
        }
        checked[index] = true;
    }

    private static boolean isIn(int innerIndex, int outerIndex) {
        long[] inner = boxes[innerIndex];
        long[] outer = boxes[outerIndex];
        return inner[0] < outer[0] && inner[1] < outer[1] && inner[2] < outer[2];
    }

}
0