結果

問題 No.1804 Intersection of LIS
ユーザー ygd.ygd.
提出日時 2022-01-09 12:42:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,763 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 193,764 KB
最終ジャッジ日時 2024-04-26 19:46:04
合計ジャッジ時間 10,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,968 KB
testcase_01 AC 38 ms
51,968 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 39 ms
52,224 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 39 ms
52,224 KB
testcase_34 WA -
testcase_35 AC 506 ms
193,764 KB
testcase_36 AC 505 ms
193,636 KB
testcase_37 AC 253 ms
132,980 KB
testcase_38 AC 257 ms
132,724 KB
testcase_39 AC 39 ms
53,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#from functools import lru_cache

def LIS(N, A): #狭義単調増加部分列
    INF = float("inf")
    #dp[i]: 最長増加部分列がi個の時の最後の値の最小値
    dp = [INF]*(N+1)
    dp[0] = -INF #iは1indexなので0の時は適当な値(-INF)を入れている。
    last_change = [INF]*(N+1)
    for i,x in enumerate(A):
        idx = bisect.bisect_left(dp, x) #x未満の数字を探して更新。
        dp[idx] = x #min(x, dp[idx])
        last_change[idx] = i
    #print(last_change)
    #ここが最長となるときの最後の更新
    last = bisect.bisect_left(last_change,INF) - 1
    last_idx = last_change[last]
    #print("last",last_idx)

    ndp = [INF]*(N+1)
    ndp[0] = -INF #iは1indexなので0の時は適当な値(-INF)を入れている。
    kouho = [set([]) for _ in range(N+1)]
    for i in range(last_idx+1):
        x = A[i]
        #print("x",x)
        idx = bisect.bisect_left(ndp, x) #x未満の数字を探して更新。
        ndp[idx] = x #min(x, dp[idx])
        kouho[idx].add(x)

    return kouho #INF未満となるIndexを返す。

def main():
    n = int(input())
    P = list(map(int,input().split()))
    ret = LIS(n,P)
    #print(ret)
    ans = []
    for S in ret:
        if len(S) == 1:
            temp = list(S); temp = temp[0]
            ans.append(temp)
    print(len(ans))
    print(*ans)

        

if __name__ == '__main__':
    main()
0