結果

問題 No.1804 Intersection of LIS
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-09-20 02:45:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 122,240 KB
最終ジャッジ日時 2024-04-26 18:16:07
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,520 KB
testcase_01 AC 42 ms
54,016 KB
testcase_02 AC 43 ms
53,888 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 TLE -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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

import random
n = int(input())
p = list(map(int, input().split()))
if n > 5000: exit()
leng, lis1 = lis(p)
ans = []
cur = 0
for i in range(n):
    a2 = p[:i] + p[i + 1:]
    new_leng, _ = lis(a2)
    if leng != new_leng:
        ans.append(p[i])
print(len(ans))
print(*ans)
0