結果
| 問題 | No.497 入れ子の箱 |
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-08 12:55:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,378 bytes |
| 記録 | |
| コンパイル時間 | 2,679 ms |
| コンパイル使用メモリ | 78,928 KB |
| 実行使用メモリ | 107,444 KB |
| 最終ジャッジ日時 | 2024-11-23 02:38:19 |
| 合計ジャッジ時間 | 65,284 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 TLE * 9 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static HashMap<Box, Integer>[] dp;
static Box[] boxes;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
dp = new HashMap[n];
boxes = new Box[n];
for (int i = 0; i < n; i++) {
boxes[i] = new Box(br.readLine());
dp[i] = new HashMap<Box, Integer>();
}
Arrays.sort(boxes);
System.out.println(dfw(n - 1, new Box(new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE})));
}
static int dfw(int idx, Box box) {
if (idx < 0) {
return 0;
}
if (dp[idx].containsKey(box)) {
return dp[idx].get(box);
}
int ans = dfw(idx - 1, box);
if (box.smaller(boxes[idx])) {
int tmp = dfw(idx - 1, boxes[idx]) + 1;
if (ans < tmp) {
ans = tmp;
box = boxes[idx];
}
}
dp[idx].put(box, ans);
return ans;
}
static class Box implements Comparable<Box> {
int[] arr = new int[3];
public Box(int[] arr) {
this.arr = arr;
Arrays.sort(arr);
}
public Box(String line) {
String[] lines = line.split(" ", 3);
for (int i = 0; i < 3; i++) {
arr[i] = Integer.parseInt(lines[i]);
}
Arrays.sort(arr);
}
public int compareTo(Box another) {
for (int i = 0; i <= 2; i++) {
if (arr[i] != another.arr[i]) {
return arr[i] - another.arr[i];
}
}
return 0;
}
public boolean equals(Object o) {
Box another = (Box)o;
for (int i = 0; i < 3; i++) {
if (arr[i] != another.arr[i]) {
return false;
}
}
return true;
}
public boolean smaller(Box another) {
for (int i = 0; i < 3; i++) {
if (arr[i] <= another.arr[i]) {
return false;
}
}
return true;
}
}
}
htensai