結果

問題 No.1804 Intersection of LIS
ユーザー 👑 ygussanyygussany
提出日時 2022-01-07 23:24:48
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 30,976 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-26 19:04:49
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,680 KB
testcase_01 AC 3 ms
7,572 KB
testcase_02 AC 3 ms
7,680 KB
testcase_03 AC 61 ms
8,808 KB
testcase_04 AC 61 ms
8,704 KB
testcase_05 AC 63 ms
8,832 KB
testcase_06 AC 61 ms
8,832 KB
testcase_07 AC 63 ms
8,832 KB
testcase_08 AC 61 ms
8,704 KB
testcase_09 AC 61 ms
8,832 KB
testcase_10 AC 62 ms
8,832 KB
testcase_11 AC 63 ms
8,832 KB
testcase_12 AC 63 ms
8,832 KB
testcase_13 AC 65 ms
8,832 KB
testcase_14 AC 63 ms
8,832 KB
testcase_15 AC 61 ms
8,832 KB
testcase_16 AC 62 ms
8,832 KB
testcase_17 AC 59 ms
8,808 KB
testcase_18 AC 3 ms
7,680 KB
testcase_19 AC 3 ms
7,552 KB
testcase_20 AC 3 ms
7,680 KB
testcase_21 AC 4 ms
7,680 KB
testcase_22 AC 4 ms
7,680 KB
testcase_23 AC 3 ms
7,552 KB
testcase_24 AC 3 ms
7,680 KB
testcase_25 AC 4 ms
7,680 KB
testcase_26 AC 3 ms
7,680 KB
testcase_27 AC 3 ms
7,680 KB
testcase_28 AC 3 ms
7,680 KB
testcase_29 AC 4 ms
7,680 KB
testcase_30 AC 3 ms
7,680 KB
testcase_31 AC 3 ms
7,680 KB
testcase_32 AC 3 ms
7,680 KB
testcase_33 AC 3 ms
7,680 KB
testcase_34 AC 3 ms
7,680 KB
testcase_35 AC 73 ms
8,704 KB
testcase_36 AC 78 ms
8,832 KB
testcase_37 AC 38 ms
8,832 KB
testcase_38 AC 38 ms
8,832 KB
testcase_39 AC 3 ms
7,680 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] = {}, lis[300001] = {};
	for (i = 1; i <= N; i++) {
		l = 0;
		r = k;
		while (l < r) {
			m = (l + r + 1) / 2;
			if (dp[m] > P[i]) r = m - 1;
			else l = m;
		}
		if (l == k) k++;
		dp[l+1] = P[i];
		lis[i] = l + 1;
	}
	
	int last[300001] = {}, ans = 0, flag[300001] = {}, num[300001] = {};
	for (i = N, last[k] = N + 1; i >= 1; i--) {
		if (P[i] < last[lis[i]]) {
			num[lis[i]]++;
			flag[i] = 1;
			if (P[i] > last[lis[i]-1]) last[lis[i]-1] = P[i];
		}
	}
	for (i = 1; i <= k; i++) if (num[i] == 1) ans++;
	printf("%d\n", ans);
	for (i = 1; i <= N; i++) if (num[lis[i]] == 1 && flag[i] != 0) printf("%d ", P[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}
0