結果

問題 No.1804 Intersection of LIS
ユーザー titiatitia
提出日時 2022-01-08 01:19:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,391 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 93,400 KB
最終ジャッジ日時 2024-04-26 19:09:49
合計ジャッジ時間 22,185 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 994 ms
48,812 KB
testcase_04 AC 969 ms
48,896 KB
testcase_05 AC 969 ms
48,900 KB
testcase_06 AC 967 ms
48,900 KB
testcase_07 AC 1,000 ms
48,836 KB
testcase_08 AC 972 ms
48,896 KB
testcase_09 AC 962 ms
49,112 KB
testcase_10 AC 963 ms
48,752 KB
testcase_11 AC 979 ms
48,900 KB
testcase_12 AC 968 ms
48,780 KB
testcase_13 AC 994 ms
48,732 KB
testcase_14 AC 949 ms
48,972 KB
testcase_15 AC 987 ms
48,928 KB
testcase_16 AC 988 ms
48,784 KB
testcase_17 AC 973 ms
48,796 KB
testcase_18 AC 38 ms
11,264 KB
testcase_19 AC 35 ms
11,264 KB
testcase_20 AC 37 ms
11,264 KB
testcase_21 AC 37 ms
11,392 KB
testcase_22 AC 37 ms
11,264 KB
testcase_23 AC 37 ms
11,264 KB
testcase_24 AC 37 ms
11,136 KB
testcase_25 AC 37 ms
11,264 KB
testcase_26 AC 37 ms
11,136 KB
testcase_27 AC 36 ms
11,264 KB
testcase_28 AC 29 ms
10,752 KB
testcase_29 AC 29 ms
10,752 KB
testcase_30 AC 28 ms
10,880 KB
testcase_31 AC 28 ms
11,008 KB
testcase_32 AC 28 ms
10,880 KB
testcase_33 AC 28 ms
10,752 KB
testcase_34 AC 28 ms
10,752 KB
testcase_35 AC 1,372 ms
93,400 KB
testcase_36 AC 1,391 ms
93,184 KB
testcase_37 AC 1,020 ms
41,468 KB
testcase_38 AC 1,011 ms
41,404 KB
testcase_39 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

# LIS(最長増加部分列)
import bisect


DP=[float("inf")]*N # DP[i]で、長さiのLISの最終要素の最小値.
POS=[-1]*N

for i in range(N):
    a=A[i]
    pos=bisect.bisect_left(DP,a)
    DP[pos]=a
    POS[i]=pos
    

ANS=0
for i in range(N):
    if DP[i]!=float("inf"): # float("inf")でない最小のものがLISの長さ
        ANS=i

LIST=[]
x=ANS
for i in range(N-1,-1,-1):
    if POS[i]==x:
        LIST.append(A[i])
        x-=1

#print(LIST)

A=[-a for a in A][::-1]

DP=[float("inf")]*N # DP[i]で、長さiのLISの最終要素の最小値.
POS=[-1]*N

for i in range(N):
    a=A[i]
    pos=bisect.bisect_left(DP,a)
    DP[pos]=a
    POS[i]=pos
    

ANS=0
for i in range(N):
    if DP[i]!=float("inf"): # float("inf")でない最小のものがLISの長さ
        ANS=i

LIST2=[]
x=ANS
for i in range(N-1,-1,-1):
    if POS[i]==x:
        LIST2.append(A[i])
        x-=1

SET=set(LIST)
SET2=set([-x for x in LIST2])

ANS=[]

A=[-a for a in A][::-1]

for a in A:
    if a in SET and a in SET2:
        ANS.append(a)
print(len(ANS))
print(*ANS)
0