結果

問題 No.497 入れ子の箱
ユーザー KilisameKilisame
提出日時 2017-05-01 09:26:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 2,260 bytes
コンパイル時間 3,964 ms
コンパイル使用メモリ 76,120 KB
実行使用メモリ 60,156 KB
最終ジャッジ日時 2023-10-12 01:58:06
合計ジャッジ時間 12,368 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,464 KB
testcase_01 AC 120 ms
55,908 KB
testcase_02 AC 120 ms
55,832 KB
testcase_03 AC 237 ms
59,808 KB
testcase_04 AC 244 ms
59,876 KB
testcase_05 AC 248 ms
59,508 KB
testcase_06 AC 244 ms
59,432 KB
testcase_07 AC 244 ms
59,896 KB
testcase_08 AC 244 ms
59,328 KB
testcase_09 AC 249 ms
59,420 KB
testcase_10 AC 245 ms
59,428 KB
testcase_11 AC 247 ms
59,840 KB
testcase_12 AC 224 ms
59,360 KB
testcase_13 AC 222 ms
58,692 KB
testcase_14 AC 222 ms
59,012 KB
testcase_15 AC 221 ms
58,880 KB
testcase_16 AC 222 ms
59,188 KB
testcase_17 AC 223 ms
58,984 KB
testcase_18 AC 239 ms
59,928 KB
testcase_19 AC 240 ms
59,984 KB
testcase_20 AC 239 ms
60,156 KB
testcase_21 AC 237 ms
59,880 KB
testcase_22 AC 241 ms
59,572 KB
testcase_23 AC 204 ms
59,068 KB
testcase_24 AC 214 ms
58,912 KB
testcase_25 AC 124 ms
55,876 KB
testcase_26 AC 124 ms
56,016 KB
testcase_27 AC 225 ms
59,036 KB
testcase_28 AC 224 ms
58,888 KB
testcase_29 AC 227 ms
59,352 KB
testcase_30 AC 219 ms
59,156 KB
testcase_31 AC 215 ms
58,776 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 int[] 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 int[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;
        for (int i = 0; i < n; i++) {
            nest(i);
        }
        System.out.println(max);
    }

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

    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