結果

問題 No.1804 Intersection of LIS
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-09-20 11:46:46
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,008 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 120,524 KB
最終ジャッジ日時 2024-04-26 18:17:30
合計ジャッジ時間 13,278 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 41 ms
52,096 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 41 ms
51,968 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 430 ms
114,324 KB
testcase_38 AC 435 ms
114,572 KB
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

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]: ans2.append(lis_min[i])
print(len(ans))
print(*ans)
0