結果

問題 No.497 入れ子の箱
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-03 22:17:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 3,825 ms
コンパイル使用メモリ 84,224 KB
実行使用メモリ 45,980 KB
最終ジャッジ日時 2024-04-15 14:47:42
合計ジャッジ時間 12,409 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
41,352 KB
testcase_01 AC 139 ms
41,364 KB
testcase_02 AC 139 ms
41,756 KB
testcase_03 AC 269 ms
45,136 KB
testcase_04 AC 277 ms
44,716 KB
testcase_05 AC 281 ms
45,024 KB
testcase_06 AC 273 ms
44,556 KB
testcase_07 AC 276 ms
44,576 KB
testcase_08 AC 277 ms
44,544 KB
testcase_09 AC 281 ms
45,164 KB
testcase_10 AC 275 ms
44,524 KB
testcase_11 AC 269 ms
45,496 KB
testcase_12 AC 277 ms
45,980 KB
testcase_13 AC 282 ms
44,724 KB
testcase_14 AC 281 ms
45,076 KB
testcase_15 AC 277 ms
44,932 KB
testcase_16 AC 280 ms
44,980 KB
testcase_17 AC 278 ms
44,920 KB
testcase_18 AC 276 ms
44,552 KB
testcase_19 AC 279 ms
45,068 KB
testcase_20 AC 282 ms
45,136 KB
testcase_21 AC 278 ms
45,148 KB
testcase_22 AC 275 ms
44,760 KB
testcase_23 AC 243 ms
44,940 KB
testcase_24 AC 253 ms
44,644 KB
testcase_25 AC 138 ms
41,444 KB
testcase_26 AC 138 ms
41,468 KB
testcase_27 AC 278 ms
44,704 KB
testcase_28 AC 284 ms
44,832 KB
testcase_29 AC 266 ms
44,548 KB
testcase_30 AC 268 ms
44,668 KB
testcase_31 AC 261 ms
44,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] x = new int[N];
    int[] y = new int[N];
    int[] z = new int[N];
    for(int i = 0; i < N; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int[] arr = {a, b, c};
      Arrays.sort(arr);
      x[i] = arr[0];
      y[i] = arr[1];
      z[i] = arr[2];
    }
    int[] bigN = new int[N];
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        if(x[i] < x[j] && y[i] < y[j] && z[i] < z[j]) bigN[i]++;
      }
    }
    int[] c = bigN.clone();
    Arrays.sort(c);
    int[] ord = new int[N];
    boolean[] used = new boolean[N];
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        if(!used[j] && bigN[j] == c[i]) {
          used[j] = true;
          ord[i] = j;
          break;
        }
      }
    }
    // dp[i]は箱ord[i]を最も内部にしたときの入れ子の最大値
    int[] dp = new int[N];
    dp[0] = 1;
    for(int i = 1; i < N; i++) {
      int a = 0;
      for(int j = 0; j < i; j++) {
        if(x[ord[i]] < x[ord[j]] && y[ord[i]] < y[ord[j]] && z[ord[i]] < z[ord[j]]) a = Math.max(a, dp[j]);
      }
      dp[i] = a + 1;
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
      ans = Math.max(ans, dp[i]);
    }
    System.out.println(ans);
  }
}
0