結果
| 問題 |
No.497 入れ子の箱
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2017-03-24 22:59:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 284 ms / 5,000 ms |
| コード長 | 1,574 bytes |
| コンパイル時間 | 2,748 ms |
| コンパイル使用メモリ | 80,884 KB |
| 実行使用メモリ | 48,152 KB |
| 最終ジャッジ日時 | 2024-07-05 23:05:22 |
| 合計ジャッジ時間 | 11,645 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int N = sc.nextInt();
boolean[][] adj = new boolean[N][N];
int[] xs = new int[N];
int[] ys = new int[N];
int[] zs = new int[N];
for(int i = 0; i < N; i++){
final int x = sc.nextInt();
final int y = sc.nextInt();
final int z = sc.nextInt();
final int min = Math.min(x, Math.min(y, z));
final int max = Math.max(x, Math.max(y, z));
final int sum = x + y + z;
xs[i] = min;
ys[i] = sum - min - max;
zs[i] = max;
}
int[] out_degree = new int[N];
int[] depth = new int[N];
for(int fst = 0; fst < N; fst++){
for(int snd = 0; snd < N; snd++){
if(fst == snd){ continue; }
if(xs[fst] < xs[snd] && ys[fst] < ys[snd] && zs[fst] < zs[snd]){
adj[fst][snd] = true;
out_degree[fst]++;
}
}
}
LinkedList<Integer> queue = new LinkedList<Integer>();
for(int i = 0; i < N; i++){
if(out_degree[i] != 0){ continue; }
queue.add(i);
depth[i] = 1;
}
while(!queue.isEmpty()){
final int node = queue.poll();
for(int from = 0; from < N; from++){
if(!adj[from][node]){ continue; }
out_degree[from]--;
depth[from] = Math.max(depth[from], depth[node] + 1);
if(out_degree[from] == 0){
queue.add(from);
}
}
}
System.out.println(Arrays.stream(depth).max().getAsInt());
}
}
uafr_cs