結果

問題 No.1804 Intersection of LIS
ユーザー 👑 ygussanyygussany
提出日時 2022-01-07 22:46:23
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 899 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-04-26 18:50:59
合計ジャッジ時間 3,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,832 KB
testcase_01 AC 3 ms
8,832 KB
testcase_02 AC 4 ms
8,960 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 2 ms
8,832 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 4 ms
8,832 KB
testcase_32 WA -
testcase_33 AC 3 ms
8,832 KB
testcase_34 WA -
testcase_35 AC 78 ms
10,052 KB
testcase_36 AC 76 ms
10,040 KB
testcase_37 AC 37 ms
10,092 KB
testcase_38 AC 37 ms
9,948 KB
testcase_39 AC 3 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main()
{
	int i, N, P[300001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	
	int k = 0, l, r, m, dp[300001] = {}, prev[300001] = {}, lis[300001] = {}, sec[300001] = {}, num[300001] = {};
	for (i = 1; i <= N; i++) {
		l = 0;
		r = k;
		while (l < r) {
			m = (l + r + 1) / 2;
			if (P[dp[m]] > P[i]) r = m - 1;
			else l = m;
		}
		if (l == k) k++;
		else sec[i] = dp[l+1];
		dp[l+1] = i;
		prev[i] = dp[l];
		num[l+1]++;
		lis[i] = l + 1;
	}
	
	int last = N + 1, ans = 0, flag[300001] = {};
	for (i = dp[k]; i > 0; i = prev[i]) flag[i] = 1;
	for (i = N; i >= 1; i--) {
		num[lis[i]]--;
		if (flag[i] != 0) {
			if (num[lis[i]] == 0 || sec[i] > last) ans++;
			else flag[i] = 0;
		}
		while (k > 0 && num[k] == 0) k--;
	}
	printf("%d\n", ans);
	for (i = 1; i <= N; i++) if (flag[i] != 0) printf("%d ", P[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}
0