結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 2021-12-06 11:53:57 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 116 ms / 5,000 ms |
コード長 | 2,784 bytes |
コンパイル時間 | 3,195 ms |
コンパイル使用メモリ | 78,868 KB |
実行使用メモリ | 54,352 KB |
最終ジャッジ日時 | 2024-07-07 08:53:47 |
合計ジャッジ時間 | 6,296 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import java.io.*;import java.util.*;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner();int n = sc.nextInt();ArrayList<ArrayList<Box>> boxes = new ArrayList<>();boxes.add(new ArrayList<>());boxes.get(0).add(new Box(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));Box[] tmp = new Box[n];for (int i = 0; i < n; i++) {tmp[i] = new Box(sc.nextInt(), sc.nextInt(), sc.nextInt());}Arrays.sort(tmp);for (Box b : tmp) {for (int j = boxes.size() - 1; j >= 0; j--) {boolean ng = true;for (Box x : boxes.get(j)) {if (x.isSmaller(b)) {ng = false;break;}}if (!ng) {if (j == boxes.size() - 1) {boxes.add(new ArrayList<>());}boxes.get(j + 1).add(b);break;}}}System.out.println(boxes.size() - 1);}static class Box implements Comparable<Box> {int big;int middle;int small;public Box(int[] arr) {Arrays.sort(arr);small = arr[0];middle = arr[1];big = arr[2];}public Box(int a, int b, int c) {this(new int[]{a, b, c});}public int compareTo(Box another) {if (big == another.big) {if (middle == another.middle) {return another.small - small;} else {return another.middle - middle;}} else {return another.big - big;}}public boolean isSmaller(Box another) {return big > another.big && middle > another.middle && small > another.small;}}}class Scanner {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer("");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 String next() throws Exception {if (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}return st.nextToken();}}