結果

問題 No.497 入れ子の箱
ユーザー 37zigen37zigen
提出日時 2017-03-24 23:12:41
言語 Java19
(openjdk 21)
結果
AC  
実行時間 244 ms / 5,000 ms
コード長 2,512 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 61,560 KB
最終ジャッジ日時 2023-09-20 03:29:23
合計ジャッジ時間 11,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,048 KB
testcase_01 AC 127 ms
55,816 KB
testcase_02 AC 127 ms
56,100 KB
testcase_03 AC 218 ms
59,764 KB
testcase_04 AC 217 ms
59,084 KB
testcase_05 AC 223 ms
59,512 KB
testcase_06 AC 219 ms
59,148 KB
testcase_07 AC 220 ms
59,064 KB
testcase_08 AC 225 ms
61,288 KB
testcase_09 AC 238 ms
59,124 KB
testcase_10 AC 228 ms
59,476 KB
testcase_11 AC 225 ms
59,284 KB
testcase_12 AC 240 ms
59,308 KB
testcase_13 AC 244 ms
59,412 KB
testcase_14 AC 244 ms
59,716 KB
testcase_15 AC 239 ms
59,532 KB
testcase_16 AC 242 ms
59,724 KB
testcase_17 AC 241 ms
59,956 KB
testcase_18 AC 235 ms
59,584 KB
testcase_19 AC 229 ms
60,192 KB
testcase_20 AC 221 ms
59,392 KB
testcase_21 AC 232 ms
59,424 KB
testcase_22 AC 230 ms
59,444 KB
testcase_23 AC 211 ms
59,372 KB
testcase_24 AC 221 ms
59,344 KB
testcase_25 AC 130 ms
55,968 KB
testcase_26 AC 126 ms
56,016 KB
testcase_27 AC 236 ms
59,732 KB
testcase_28 AC 234 ms
61,560 KB
testcase_29 AC 240 ms
60,220 KB
testcase_30 AC 236 ms
59,376 KB
testcase_31 AC 236 ms
59,192 KB
権限があれば一括ダウンロードができます

ソースコード

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);
		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