結果

問題 No.1804 Intersection of LIS
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-09-27 23:26:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 150,896 KB
最終ジャッジ日時 2024-04-26 18:17:50
合計ジャッジ時間 12,580 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 41 ms
51,840 KB
testcase_02 WA -
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 41 ms
52,480 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 550 ms
150,896 KB
testcase_36 AC 542 ms
150,736 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 38 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

INF = 10 ** 9
def lis(x):
    dp = [INF] * (len(x) + 1)
    id = [0] * len(x)
    for i in range(len(x)):
        id[i] = bisect_left(dp, x[i])
        dp[bisect_left(dp, x[i])] = x[i]
    m = max(id)
    b = [0] * (m + 1)
    for i in range(len(x) - 1, -1, -1):
        if id[i] == m:
            b[m] = x[i]
            m -= 1
    return bisect_left(dp, INF), b
def lds(x):
    dp = [-INF] * (len(x) + 1)
    id = [0] * len(x)
    for i in range(len(x)):
        id[i] = bisect_left(dp, x[i]) - 1
        dp[bisect_left(dp, x[i]) - 1] = x[i]
    m = min(id)
    b = [0] * (max(id) + 1)
    for i in range(len(x))[::-1]:
        if id[i] == m:
            b[m] = x[i]
            m += 1
    return dp[::-1].index(-INF), b

n = int(input())
p = list(map(int, input().split()))
leng, lis_min = lis(p)
_, lis_max = lds(p[::-1])
lis_max = lis_max[::-1][:leng][::-1]
ans = []
for i in range(len(lis_min)):
    if lis_min[i] == lis_max[i]: ans.append(lis_min[i])
print(len(lis_min))
print(*lis_min)
0