結果
問題 | No.497 入れ子の箱 |
ユーザー | 37zigen |
提出日時 | 2017-03-24 23:13:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 235 ms / 5,000 ms |
コード長 | 2,292 bytes |
コンパイル時間 | 2,314 ms |
コンパイル使用メモリ | 76,340 KB |
実行使用メモリ | 60,868 KB |
最終ジャッジ日時 | 2023-09-20 03:30:48 |
合計ジャッジ時間 | 10,249 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 125 ms
56,036 KB |
testcase_01 | AC | 125 ms
56,068 KB |
testcase_02 | AC | 123 ms
55,856 KB |
testcase_03 | AC | 211 ms
59,292 KB |
testcase_04 | AC | 221 ms
59,528 KB |
testcase_05 | AC | 218 ms
59,580 KB |
testcase_06 | AC | 219 ms
59,564 KB |
testcase_07 | AC | 221 ms
59,360 KB |
testcase_08 | AC | 218 ms
59,624 KB |
testcase_09 | AC | 219 ms
59,664 KB |
testcase_10 | AC | 225 ms
60,868 KB |
testcase_11 | AC | 224 ms
59,168 KB |
testcase_12 | AC | 231 ms
59,316 KB |
testcase_13 | AC | 234 ms
59,248 KB |
testcase_14 | AC | 235 ms
59,724 KB |
testcase_15 | AC | 219 ms
59,152 KB |
testcase_16 | AC | 226 ms
59,600 KB |
testcase_17 | AC | 227 ms
59,236 KB |
testcase_18 | AC | 227 ms
59,644 KB |
testcase_19 | AC | 209 ms
59,516 KB |
testcase_20 | AC | 221 ms
57,280 KB |
testcase_21 | AC | 222 ms
59,536 KB |
testcase_22 | AC | 222 ms
59,332 KB |
testcase_23 | AC | 202 ms
59,520 KB |
testcase_24 | AC | 210 ms
59,460 KB |
testcase_25 | AC | 124 ms
56,272 KB |
testcase_26 | AC | 121 ms
55,976 KB |
testcase_27 | AC | 226 ms
59,732 KB |
testcase_28 | AC | 214 ms
59,372 KB |
testcase_29 | AC | 226 ms
59,608 KB |
testcase_30 | AC | 229 ms
59,548 KB |
testcase_31 | AC | 234 ms
59,144 KB |
ソースコード
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); } 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)); } }