結果

問題 No.497 入れ子の箱
ユーザー uafr_csuafr_cs
提出日時 2017-03-24 22:59:29
言語 Java19
(openjdk 21)
結果
AC  
実行時間 286 ms / 5,000 ms
コード長 1,574 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 78,500 KB
実行使用メモリ 61,564 KB
最終ジャッジ日時 2023-09-20 02:44:57
合計ジャッジ時間 11,923 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,616 KB
testcase_01 AC 129 ms
56,132 KB
testcase_02 AC 128 ms
55,960 KB
testcase_03 AC 276 ms
60,672 KB
testcase_04 AC 284 ms
59,268 KB
testcase_05 AC 278 ms
60,904 KB
testcase_06 AC 286 ms
58,840 KB
testcase_07 AC 284 ms
59,324 KB
testcase_08 AC 276 ms
59,088 KB
testcase_09 AC 285 ms
59,244 KB
testcase_10 AC 279 ms
59,312 KB
testcase_11 AC 284 ms
59,328 KB
testcase_12 AC 285 ms
59,240 KB
testcase_13 AC 282 ms
59,416 KB
testcase_14 AC 280 ms
59,564 KB
testcase_15 AC 284 ms
59,564 KB
testcase_16 AC 283 ms
59,436 KB
testcase_17 AC 286 ms
59,088 KB
testcase_18 AC 268 ms
59,348 KB
testcase_19 AC 272 ms
59,540 KB
testcase_20 AC 268 ms
59,412 KB
testcase_21 AC 274 ms
59,628 KB
testcase_22 AC 271 ms
58,924 KB
testcase_23 AC 244 ms
59,840 KB
testcase_24 AC 239 ms
58,796 KB
testcase_25 AC 128 ms
55,860 KB
testcase_26 AC 130 ms
56,004 KB
testcase_27 AC 282 ms
59,500 KB
testcase_28 AC 279 ms
59,188 KB
testcase_29 AC 278 ms
59,972 KB
testcase_30 AC 262 ms
61,564 KB
testcase_31 AC 263 ms
59,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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());
	}
}
0