結果
問題 | No.1804 Intersection of LIS |
ユーザー |
👑 ![]() |
提出日時 | 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 |
ソースコード
"""https://yukicoder.me/problems/no/1804辞書順最大・最小のLISを見付ける"""import sysfrom sys import stdin#return lexicography minimum LISdef LISMIN(lis):import bisectdic = {}seq = []for c in lis:ind = bisect.bisect_left(seq,c)if ind == len(seq):seq.append(c)if len(seq) == 1:dic[c] = Noneelse:dic[c] = seq[-2]else:seq[ind] = cif ind == 0:dic[c] = Noneelse:dic[c] = seq[ind-1]#print (seq)ret = []v = seq[-1]while v != None:ret.append(v)v = dic[v]ret.reverse()return retN = int(stdin.readline())P = list(map(int,stdin.readline().split()))LM = LISMIN(P)P.reverse()for i in range(N):P[i] *= -1RM = LISMIN(P)RM.reverse()for i in range(len(RM)):RM[i] *= -1ans = []for i in range(len(LM)):if LM[i] == RM[i]:ans.append(LM[i])print (len(ans))print (*ans)