結果

問題 No.1804 Intersection of LIS
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2022-01-08 03:48:44
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 1,067 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 212 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 223,700 KB
最終ジャッジ日時 2026-05-09 22:05:06
合計ジャッジ時間 7,967 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

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