結果

問題 No.497 入れ子の箱
ユーザー KilisameKilisame
提出日時 2017-04-28 16:23:39
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,644 bytes
コンパイル時間 3,891 ms
コンパイル使用メモリ 81,140 KB
実行使用メモリ 65,608 KB
最終ジャッジ日時 2023-10-11 18:54:42
合計ジャッジ時間 11,615 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,708 KB
testcase_01 AC 120 ms
55,696 KB
testcase_02 AC 121 ms
55,580 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/* とりあえず総当たり */
public class Main {

    private static int n;

    private static long[][] boxes;

    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];
        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] && o1[1] < o2[1] && o1[2] < o2[2]) {
                    return -1;
                } else if (o1[0] > o2[0] && o1[1] > o2[1] && 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) {
        for (int i = index + 1; i < n; i++) {
            if (isIn(index, i)) {
                nest(i, count + 1);
            }
        }
        if (count > max) {
            max = count;
        }
    }

    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