結果

問題 No.1804 Intersection of LIS
ユーザー SPD_9X2
提出日時 2022-01-08 03:48:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 251,696 KB
最終ジャッジ日時 2024-11-14 09:23:32
合計ジャッジ時間 10,615 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1804

辞書順最大・最小のLISを見付ける

"""

import sys
from sys import stdin

#return lexicography minimum LIS
def LISMIN(lis):
    import bisect

    dic = {}
    
    seq = []
    for c in lis:
        ind = bisect.bisect_left(seq,c)
        if ind == len(seq):
            seq.append(c)
            if len(seq) == 1:
                dic[c] = None
            else:
                dic[c] = seq[-2]
        else:
            seq[ind] = c
            if ind == 0:
                dic[c] = None
            else:
                dic[c] = seq[ind-1]

    #print (seq)
    ret = []
    v = seq[-1]
    while v != None:
        ret.append(v)
        v = dic[v]
    ret.reverse()

    return ret
    

N = int(stdin.readline())
P = list(map(int,stdin.readline().split()))

LM = LISMIN(P)

P.reverse()
for i in range(N):
    P[i] *= -1
RM = LISMIN(P)
RM.reverse()
for i in range(len(RM)):
    RM[i] *= -1

ans = []
for i in range(len(LM)):
    if LM[i] == RM[i]:
        ans.append(LM[i])
print (len(ans))
print (*ans)
0