結果

問題 No.1804 Intersection of LIS
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-09-20 02:35:56
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,037 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 151,156 KB
最終ジャッジ日時 2024-04-26 18:15:43
合計ジャッジ時間 12,043 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,224 KB
testcase_01 AC 36 ms
52,480 KB
testcase_02 WA -
testcase_03 AC 454 ms
114,896 KB
testcase_04 AC 463 ms
114,492 KB
testcase_05 AC 448 ms
114,516 KB
testcase_06 AC 477 ms
114,436 KB
testcase_07 AC 467 ms
114,388 KB
testcase_08 AC 468 ms
114,568 KB
testcase_09 AC 465 ms
114,696 KB
testcase_10 AC 493 ms
114,896 KB
testcase_11 AC 456 ms
114,708 KB
testcase_12 AC 460 ms
114,692 KB
testcase_13 AC 466 ms
114,648 KB
testcase_14 AC 458 ms
114,824 KB
testcase_15 AC 450 ms
114,932 KB
testcase_16 AC 459 ms
114,948 KB
testcase_17 AC 463 ms
114,396 KB
testcase_18 AC 65 ms
75,776 KB
testcase_19 AC 64 ms
76,160 KB
testcase_20 AC 66 ms
76,000 KB
testcase_21 AC 64 ms
75,648 KB
testcase_22 AC 65 ms
75,888 KB
testcase_23 AC 67 ms
76,156 KB
testcase_24 AC 65 ms
75,752 KB
testcase_25 AC 66 ms
75,896 KB
testcase_26 AC 66 ms
75,776 KB
testcase_27 AC 66 ms
76,276 KB
testcase_28 AC 39 ms
52,480 KB
testcase_29 AC 38 ms
52,864 KB
testcase_30 AC 38 ms
52,352 KB
testcase_31 AC 37 ms
52,480 KB
testcase_32 AC 37 ms
52,352 KB
testcase_33 WA -
testcase_34 AC 37 ms
52,224 KB
testcase_35 AC 502 ms
150,952 KB
testcase_36 AC 506 ms
151,156 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 40 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

INF = 10 ** 9
def lis(x):
    dp = [INF] * (len(x) + 1)
    id = [0] * len(x)
    for i in range(len(x)):
        id[i] = bisect_left(dp, x[i])
        dp[bisect_left(dp, x[i])] = x[i]
    m = max(id)
    b = [0] * (m + 1)
    for i in range(len(x) - 1, -1, -1):
        if id[i] == m:
            b[m] = x[i]
            m -= 1
    return bisect_left(dp, INF), b
def lds(x):
    dp = [-INF] * (len(x) + 1)
    id = [0] * len(x)
    for i in range(len(x)):
        id[i] = bisect_left(dp, x[i]) - 1
        dp[bisect_left(dp, x[i]) - 1] = x[i]
    m = min(id)
    b = [0] * (max(id) + 1)
    for i in range(len(x))[::-1]:
        if id[i] == m:
            b[m] = x[i]
            m += 1
    return dp[::-1].index(-INF), b

n = int(input())
p = list(map(int, input().split()))
leng, lis_min = lis(p)
_, lis_max = lds(p[::-1])
lis_max = lis_max[::-1][:leng][::-1]
ans2 = []
for i in range(len(lis_min)):
    if lis_min[i] == lis_max[i]: ans2.append(lis_min[i])
print(len(ans2))
if len(ans2) == 0: exit()
print(*ans2)
0