結果

問題 No.1804 Intersection of LIS
ユーザー 👑 rin204rin204
提出日時 2022-01-25 01:17:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 222,852 KB
最終ジャッジ日時 2023-08-21 16:46:12
合計ジャッジ時間 11,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,308 KB
testcase_01 AC 70 ms
71,476 KB
testcase_02 AC 70 ms
71,404 KB
testcase_03 AC 295 ms
122,040 KB
testcase_04 AC 295 ms
122,316 KB
testcase_05 AC 293 ms
122,504 KB
testcase_06 AC 292 ms
122,040 KB
testcase_07 AC 295 ms
122,432 KB
testcase_08 AC 299 ms
122,240 KB
testcase_09 AC 291 ms
122,308 KB
testcase_10 AC 296 ms
121,712 KB
testcase_11 AC 297 ms
122,016 KB
testcase_12 AC 295 ms
121,960 KB
testcase_13 AC 296 ms
122,000 KB
testcase_14 AC 299 ms
122,128 KB
testcase_15 AC 293 ms
122,016 KB
testcase_16 AC 300 ms
122,044 KB
testcase_17 AC 296 ms
122,056 KB
testcase_18 AC 95 ms
77,020 KB
testcase_19 AC 92 ms
77,156 KB
testcase_20 AC 94 ms
76,908 KB
testcase_21 AC 91 ms
77,344 KB
testcase_22 AC 93 ms
77,232 KB
testcase_23 AC 92 ms
77,228 KB
testcase_24 AC 92 ms
76,236 KB
testcase_25 AC 93 ms
76,944 KB
testcase_26 AC 92 ms
76,880 KB
testcase_27 AC 100 ms
77,588 KB
testcase_28 AC 71 ms
71,492 KB
testcase_29 AC 70 ms
71,280 KB
testcase_30 AC 72 ms
71,464 KB
testcase_31 AC 71 ms
71,468 KB
testcase_32 AC 71 ms
71,348 KB
testcase_33 AC 72 ms
71,476 KB
testcase_34 AC 73 ms
71,532 KB
testcase_35 AC 379 ms
222,852 KB
testcase_36 AC 374 ms
222,796 KB
testcase_37 AC 211 ms
122,120 KB
testcase_38 AC 209 ms
122,220 KB
testcase_39 AC 72 ms
71,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

n = int(input())
P = list(map(int, input().split()))

def f(P):
    bef = [-1] * n
    lis = [0] * n
    lst = []
    pos = []
    for i, p in enumerate(P):
        j = bisect_left(lst, p)
        if len(lst) == j:
            lst.append(p)
            pos.append(i)
        else:
            lst[j] = p
            pos[j] = i
        lis[i] = j
        if j != 0:
            bef[i] = pos[j - 1]
    
    p = pos[-1]
    left = []
    while p != -1:
        left.append(P[p])
        p = bef[p]
    return left

left = f(P)[::-1]
P = P[::-1]
P = [-p for p in P]
right = f(P)
right = [-p for p in right]
ans = [l for l, r in zip(left, right) if l == r]
print(len(ans))
print(*ans)



0