結果

問題 No.1804 Intersection of LIS
ユーザー kozy
提出日時 2022-01-07 22:57:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 673 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 73,016 KB
最終ジャッジ日時 2024-11-14 09:01:41
合計ジャッジ時間 9,569 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import bisect
#i番目までの増加列の長さを返す
def LIS(lis):
  c=len(lis)
  dp=[lis[0]]
  this=0
  ansl=[]
  for i in range(c):
    a=lis[i]
    if a>dp[-1]:
      dp.append(a)
      this=len(dp)-1
    else:
      x=bisect.bisect_left(dp,a)
      this=x
      dp[x]=a
    ansl.append(this)
  return ansl

N=int(input())
P=list(map(int,input().split()))
L=LIS(P)
this=0
K=list()
K2=list()
for i in range(len(L)):
  if L[i]==this:
    K.append(i)
    this+=1
this=max(L)
for i in range(len(L)-1,-1,-1):
  if L[i]==this:
    K2.append(i)
    this-=1
K2=set(K2)
ansl=list()
for i in K:
  if i in K2:
    ansl.append(P[i])
print(len(ansl))
print(*ansl)
0