結果

問題 No.1804 Intersection of LIS
ユーザー ShirotsumeShirotsume
提出日時 2022-07-27 15:19:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 86,400 KB
実行使用メモリ 234,984 KB
最終ジャッジ日時 2023-09-24 03:52:28
合計ジャッジ時間 11,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,404 KB
testcase_01 AC 66 ms
71,056 KB
testcase_02 AC 62 ms
71,020 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 62 ms
71,244 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 63 ms
71,392 KB
testcase_32 WA -
testcase_33 AC 62 ms
71,420 KB
testcase_34 WA -
testcase_35 AC 405 ms
234,984 KB
testcase_36 AC 390 ms
234,744 KB
testcase_37 AC 190 ms
122,316 KB
testcase_38 AC 192 ms
122,260 KB
testcase_39 AC 61 ms
71,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
INF = 2 ** 63 - 1
mod = 998244353
import bisect
n = ii()
a = li()
def LIS1(a):

    dp = [INF] * n

    ind = [-1] * n

    for i in range(n):
        now = bisect.bisect_left(dp, a[i])
        dp[now] = a[i]
        ind[i] = now

    k = max(ind) + 1
    ans = [0] * k
    k -= 1
    for i in range(n - 1, -1, -1):
        if ind[i] == k:
            ans[k] = i
            k -= 1
    return ans

def LIS2(a):
    dp = [INF] * n

    ind = [-1] * n

    for i in range(n):
        now = bisect.bisect_left(dp, a[i])
        dp[now] = a[i]
        ind[i] = now

    k = max(ind) + 1
    ans = [0] * k
    k = 0
    for i in range(n):
        if ind[i] == k:
            ans[k] = i
            k += 1
    return ans

ans1 = set(LIS1(a))
ans2 = set(LIS2(a))
ans = ans1 & ans2

ans = list(sorted(ans))

print(len(ans))
print(*[a[i] for i in ans])


0