結果

問題 No.1804 Intersection of LIS
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-09-20 02:41:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 151,016 KB
最終ジャッジ日時 2024-04-26 18:16:31
合計ジャッジ時間 11,470 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,480 KB
testcase_01 WA -
testcase_02 AC 39 ms
51,968 KB
testcase_03 AC 461 ms
114,184 KB
testcase_04 AC 454 ms
114,244 KB
testcase_05 AC 455 ms
114,384 KB
testcase_06 AC 456 ms
114,432 KB
testcase_07 AC 443 ms
114,188 KB
testcase_08 AC 459 ms
114,568 KB
testcase_09 AC 434 ms
114,308 KB
testcase_10 AC 440 ms
114,444 KB
testcase_11 AC 461 ms
114,312 KB
testcase_12 AC 454 ms
114,436 KB
testcase_13 AC 445 ms
114,692 KB
testcase_14 AC 448 ms
114,440 KB
testcase_15 AC 440 ms
114,180 KB
testcase_16 AC 467 ms
114,568 KB
testcase_17 AC 451 ms
114,300 KB
testcase_18 AC 77 ms
75,520 KB
testcase_19 AC 68 ms
75,904 KB
testcase_20 AC 71 ms
75,520 KB
testcase_21 AC 74 ms
75,520 KB
testcase_22 AC 73 ms
75,520 KB
testcase_23 AC 73 ms
75,648 KB
testcase_24 AC 72 ms
75,392 KB
testcase_25 AC 71 ms
75,520 KB
testcase_26 AC 69 ms
75,392 KB
testcase_27 AC 71 ms
75,520 KB
testcase_28 WA -
testcase_29 AC 40 ms
52,096 KB
testcase_30 AC 36 ms
52,096 KB
testcase_31 AC 37 ms
51,968 KB
testcase_32 AC 37 ms
52,096 KB
testcase_33 AC 35 ms
52,608 KB
testcase_34 AC 38 ms
52,224 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 391 ms
114,312 KB
testcase_38 AC 388 ms
114,304 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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) == leng: print("!")
print(*ans2)
0