結果

問題 No.1804 Intersection of LIS
ユーザー ks2mks2m
提出日時 2022-01-07 23:02:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,526 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 78,344 KB
実行使用メモリ 91,376 KB
最終ジャッジ日時 2024-04-26 18:58:10
合計ジャッジ時間 15,376 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,072 KB
testcase_01 AC 51 ms
37,016 KB
testcase_02 AC 52 ms
36,520 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 50 ms
37,132 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 51 ms
37,000 KB
testcase_34 WA -
testcase_35 AC 592 ms
91,376 KB
testcase_36 AC 594 ms
91,376 KB
testcase_37 AC 426 ms
78,936 KB
testcase_38 AC 419 ms
78,692 KB
testcase_39 AC 52 ms
37,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] dp = new int[n + 1];
		List<List<Integer>> list = new ArrayList<>(n + 1);
		list.add(new ArrayList<>());
		for (int i = 1; i <= n; i++) {
			dp[i] = Integer.MAX_VALUE;
			list.add(new ArrayList<>());
		}

		for (int i = 0; i < n; i++) {
			int idx = Arrays.binarySearch(dp, a[i]);
			if (idx < 0) idx = ~idx;
			dp[idx] = a[i];
			list.get(idx).add(i);
		}

		int lis = Arrays.binarySearch(dp, Integer.MAX_VALUE - 1);
		if (lis < 0) {
			lis = ~lis;
			lis--;
		}

		List<Integer> list2 = list.get(lis);
		int size = list2.size();
		int x = list2.get(size - 1);

		int cnt = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= lis; i++) {
			List<Integer> wk = list.get(i);
			int num = 0;
			for (int j = wk.size() - 1; j >= 0; j--) {
				if (wk.get(j) <= x) {
					num = j + 1;
					break;
				}
			}
			if (num == 1) {
				sb.append(a[wk.get(0)]).append(' ');
				cnt++;
			}
		}
		if (cnt > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		System.out.println(cnt);
		System.out.println(sb.toString());
	}
}
0