結果

問題 No.497 入れ子の箱
ユーザー 37zigen37zigen
提出日時 2017-03-24 23:11:51
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 2,563 bytes
コンパイル時間 2,786 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 62,248 KB
最終ジャッジ日時 2023-09-20 03:27:48
合計ジャッジ時間 11,342 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	boolean check(TreeSet<int[]> C, int[] S) {
		int[] Sl = C.lower(S);
		if (Sl != null && Sl[1] < S[1]) {
			return true;
		} else {
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	void solve(int N, int[][] S) {
		TreeSet<int[]>[] C = new TreeSet[N];
		for (int i = 0; i < N; ++i) {
			C[i] = new TreeSet<>(new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0]) {
						return Integer.compare(o1[0], o2[0]);
					} else {
						return -Integer.compare(o1[1], o2[1]);
					}
				}
			});
		}
		C[0].add(S[0]);
		int maxLen = 1;
		for (int i = 1; i < N; ++i) {
			int left = -1;
			int right = maxLen;
			while (right - left > 1) {
				int middle = (right + left) / 2;
				if (check(C[middle], S[i])) {
					left = middle;
				} else {
					right = middle;
				}
			}

			if (left + 1 == maxLen) {
				C[left + 1].add(S[i]);
				++maxLen;
				continue;
			} else {
				int[] tmp = C[left + 1].floor(S[i]);
				if (tmp != null && tmp[1] == S[i][1])
					continue;
				tmp = C[left + 1].higher(S[i]);
				while (tmp != null && S[i][1] <= tmp[1]) {
					C[left + 1].remove(tmp);
					tmp = C[left + 1].higher(S[i]);
				}
				C[left + 1].add(S[i]);
			}
		}
		System.out.println(maxLen);
	}

	int nextA(int a, int M) {
		return 36969 * (a & M) + (a >> 16);
	}

	int nextB(int b, int M) {
		return 18000 * (b & M) + (b >> 16);
	}

	int nextVal(int a, int b, int C) {
		return (C & ((a << 16) + b)) % 1000000;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int[][] S = new int[n][3];
			for (int i = 0; i < n; ++i) {
				int[] a = new int[3];
				a[0] = sc.nextInt();
				a[1] = sc.nextInt();
				a[2] = sc.nextInt();
				Arrays.sort(a);
				S[i][0] = a[0];
				S[i][1] = a[1];
				S[i][2] = a[2];
			}
			Arrays.sort(S, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0])
						return Integer.compare(o1[0], o2[0]);
					else if (o1[1] != o2[1]) {
						return -Integer.compare(o1[1], o2[1]);
					} else {
						return -Integer.compare(o1[2], o2[2]);
					}
				}
			});

			int[][] tmp = new int[n][2];
			for (int i = 0; i < n; ++i) {
				tmp[i][0] = S[i][1];
				tmp[i][1] = S[i][2];
			}
			solve(n, tmp);

		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0