結果
問題 | No.497 入れ子の箱 |
ユーザー | tenten |
提出日時 | 2023-01-30 20:12:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 204 ms / 5,000 ms |
コード長 | 2,977 bytes |
コンパイル時間 | 4,216 ms |
コンパイル使用メモリ | 80,856 KB |
実行使用メモリ | 59,500 KB |
最終ジャッジ日時 | 2023-09-12 17:37:22 |
合計ジャッジ時間 | 9,634 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
50,088 KB |
testcase_01 | AC | 46 ms
49,616 KB |
testcase_02 | AC | 45 ms
49,820 KB |
testcase_03 | AC | 151 ms
58,636 KB |
testcase_04 | AC | 178 ms
59,036 KB |
testcase_05 | AC | 160 ms
58,784 KB |
testcase_06 | AC | 158 ms
58,904 KB |
testcase_07 | AC | 193 ms
58,888 KB |
testcase_08 | AC | 186 ms
58,784 KB |
testcase_09 | AC | 166 ms
59,500 KB |
testcase_10 | AC | 179 ms
58,944 KB |
testcase_11 | AC | 161 ms
58,836 KB |
testcase_12 | AC | 182 ms
58,880 KB |
testcase_13 | AC | 169 ms
58,456 KB |
testcase_14 | AC | 178 ms
58,784 KB |
testcase_15 | AC | 176 ms
58,852 KB |
testcase_16 | AC | 184 ms
58,580 KB |
testcase_17 | AC | 179 ms
58,936 KB |
testcase_18 | AC | 189 ms
59,168 KB |
testcase_19 | AC | 170 ms
58,856 KB |
testcase_20 | AC | 185 ms
58,828 KB |
testcase_21 | AC | 194 ms
58,840 KB |
testcase_22 | AC | 187 ms
58,832 KB |
testcase_23 | AC | 112 ms
58,224 KB |
testcase_24 | AC | 130 ms
58,320 KB |
testcase_25 | AC | 47 ms
49,624 KB |
testcase_26 | AC | 47 ms
49,624 KB |
testcase_27 | AC | 204 ms
58,304 KB |
testcase_28 | AC | 170 ms
58,936 KB |
testcase_29 | AC | 170 ms
58,792 KB |
testcase_30 | AC | 150 ms
58,236 KB |
testcase_31 | AC | 150 ms
58,064 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static Box[] boxes; static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); boxes = new Box[n + 1]; for (int i = 0; i < n; i++) { boxes[i] = new Box(sc.nextInt(), sc.nextInt(), sc.nextInt()); } boxes[n] = new Box(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); Arrays.sort(boxes); dp = new int[n][n + 1]; for (int[] arr : dp) { Arrays.fill(arr, -1); } System.out.println(dfw(n - 1, n)); } static int dfw(int idx, int b) { if (idx < 0) { return 0; } if (dp[idx][b] < 0) { dp[idx][b] = dfw(idx - 1, b); if (boxes[idx].isSmaller(boxes[b])) { dp[idx][b] = Math.max(dp[idx][b], dfw(idx - 1, idx) + 1); } } return dp[idx][b]; } static class Box implements Comparable<Box> { int[] arr; public Box(int a, int b, int c) { arr = new int[]{a, b, c}; Arrays.sort(arr); } public int compareTo(Box another) { for (int i = 2; i >= 0; i--) { if (arr[i] != another.arr[i]) { return arr[i] - another.arr[i]; } } return 0; } public boolean isSmaller(Box another) { for (int i = 0; i < 3; i++) { if (arr[i] >= another.arr[i]) { return false; } } return true; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }