結果

問題 No.1804 Intersection of LIS
ユーザー 👑 ygussanyygussany
提出日時 2022-01-07 23:12:37
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-26 19:02:45
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,264 KB
testcase_01 AC 7 ms
11,264 KB
testcase_02 AC 7 ms
11,264 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 7 ms
11,264 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 7 ms
11,264 KB
testcase_32 AC 7 ms
11,264 KB
testcase_33 AC 7 ms
11,264 KB
testcase_34 AC 7 ms
11,264 KB
testcase_35 AC 84 ms
12,416 KB
testcase_36 AC 85 ms
12,416 KB
testcase_37 AC 41 ms
12,416 KB
testcase_38 AC 41 ms
12,416 KB
testcase_39 AC 7 ms
11,264 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] = {}, sec[300001] = {}, prev[300001] = {}, lis[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] = P[dp[l+1]];
		dp[l+1] = i;
		prev[i] = dp[l];
		num[l+1]++;
		lis[i] = l + 1;
	}
	
	int last[300001] = {}, ans = 0, flag[300001] = {}, cand[300001] = {};
	for (i = dp[k]; i > 0; i = prev[i]) flag[i] = 1;
	for (i = N, last[k] = N + 1; i >= 1; i--) {
		num[lis[i]]--;
		if (flag[i] != 0) {
			if (k == lis[i] && (num[lis[i]] == 0 || sec[i] > last[lis[i]]) && cand[lis[i]] >= 0) ans++;
			else flag[i] = 0;
		}
		if (P[i] < last[lis[i]]) {
			if (P[i] > last[lis[i]-1]) last[lis[i]-1] = P[i];
			if (cand[lis[i]-1] == 0) cand[lis[i]-1] = prev[i];
			else if (cand[lis[i]-1] != prev[i]) cand[lis[i]-1] = -1;
		}
		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