結果

問題 No.1804 Intersection of LIS
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-01-08 03:48:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 437 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 251,668 KB
最終ジャッジ日時 2024-04-26 19:11:16
合計ジャッジ時間 10,724 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 39 ms
52,352 KB
testcase_02 AC 39 ms
51,840 KB
testcase_03 AC 418 ms
171,256 KB
testcase_04 AC 416 ms
173,772 KB
testcase_05 AC 408 ms
173,824 KB
testcase_06 AC 388 ms
171,148 KB
testcase_07 AC 409 ms
173,392 KB
testcase_08 AC 429 ms
173,792 KB
testcase_09 AC 419 ms
173,420 KB
testcase_10 AC 417 ms
171,752 KB
testcase_11 AC 412 ms
174,328 KB
testcase_12 AC 408 ms
171,192 KB
testcase_13 AC 410 ms
171,616 KB
testcase_14 AC 412 ms
173,500 KB
testcase_15 AC 417 ms
171,572 KB
testcase_16 AC 421 ms
173,504 KB
testcase_17 AC 426 ms
171,736 KB
testcase_18 AC 69 ms
72,192 KB
testcase_19 AC 65 ms
72,488 KB
testcase_20 AC 64 ms
72,320 KB
testcase_21 AC 62 ms
71,424 KB
testcase_22 AC 66 ms
72,192 KB
testcase_23 AC 65 ms
71,424 KB
testcase_24 AC 63 ms
71,552 KB
testcase_25 AC 65 ms
72,448 KB
testcase_26 AC 64 ms
71,808 KB
testcase_27 AC 69 ms
74,112 KB
testcase_28 AC 38 ms
52,352 KB
testcase_29 AC 41 ms
52,224 KB
testcase_30 AC 40 ms
51,840 KB
testcase_31 AC 39 ms
52,352 KB
testcase_32 AC 39 ms
52,352 KB
testcase_33 AC 38 ms
52,096 KB
testcase_34 AC 38 ms
52,096 KB
testcase_35 AC 437 ms
251,668 KB
testcase_36 AC 426 ms
251,292 KB
testcase_37 AC 239 ms
153,204 KB
testcase_38 AC 240 ms
153,328 KB
testcase_39 AC 38 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

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