結果

問題 No.1804 Intersection of LIS
ユーザー mkawa2mkawa2
提出日時 2023-12-08 15:41:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 170,228 KB
最終ジャッジ日時 2023-12-08 15:42:02
合計ジャッジ時間 8,724 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 243 ms
112,440 KB
testcase_04 AC 243 ms
112,440 KB
testcase_05 AC 248 ms
112,440 KB
testcase_06 AC 246 ms
112,436 KB
testcase_07 AC 246 ms
112,564 KB
testcase_08 AC 253 ms
112,436 KB
testcase_09 AC 240 ms
112,564 KB
testcase_10 AC 279 ms
112,436 KB
testcase_11 AC 240 ms
112,436 KB
testcase_12 AC 241 ms
112,440 KB
testcase_13 AC 258 ms
112,436 KB
testcase_14 AC 263 ms
112,692 KB
testcase_15 AC 246 ms
112,436 KB
testcase_16 AC 259 ms
112,436 KB
testcase_17 AC 256 ms
112,440 KB
testcase_18 AC 59 ms
72,620 KB
testcase_19 AC 60 ms
72,636 KB
testcase_20 AC 58 ms
70,552 KB
testcase_21 AC 59 ms
70,552 KB
testcase_22 AC 60 ms
72,640 KB
testcase_23 AC 59 ms
70,552 KB
testcase_24 AC 58 ms
70,552 KB
testcase_25 AC 60 ms
72,636 KB
testcase_26 AC 58 ms
70,552 KB
testcase_27 AC 61 ms
72,768 KB
testcase_28 AC 36 ms
53,460 KB
testcase_29 AC 36 ms
53,460 KB
testcase_30 AC 36 ms
53,460 KB
testcase_31 AC 36 ms
53,460 KB
testcase_32 AC 36 ms
53,460 KB
testcase_33 AC 36 ms
53,460 KB
testcase_34 AC 36 ms
53,460 KB
testcase_35 AC 282 ms
170,228 KB
testcase_36 AC 282 ms
170,224 KB
testcase_37 AC 163 ms
112,180 KB
testcase_38 AC 164 ms
112,180 KB
testcase_39 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

from bisect import bisect

n=II()
pp=LI()

lis=[]
dist=[0]*n
for i,p in enumerate(pp):
    j=bisect(lis,p)
    dist[i]=j
    if j==len(lis):
        lis.append(p)
    else:
        lis[j]=p

mx=len(lis)-1
lis=[]
ok=[]
idx=[]
for i in range(n)[::-1]:
    j=bisect(lis,-pp[i])
    if dist[i]+j!=mx:continue
    if j==len(lis):
        lis.append(-pp[i])
        ok.append(1)
    else:
        lis[j]=-pp[i]
        ok[j]=0

ans=[]
for p,j in zip(lis,ok):
    if j:ans.append(-p)

ans.reverse()
print(len(ans))
print(*ans)
0