목차

데크 소트 2

ps
링크acmicpc.net/…
출처BOJ
문제 번호10975
문제명데크 소트 2
레벨실버 1
분류

그리디

시간복잡도O(nlogn)
인풋사이즈n<=50
사용한 언어Python
제출기록30864KB / 76ms
최고기록68ms
해결날짜2022/01/24

풀이

코드

"""Solution code for "BOJ 10975. 데크 소트 2".

- Problem link: https://www.acmicpc.net/problem/10975
- Solution link: http://www.teferi.net/ps/problems/boj/10975
"""


def main():
    N = int(input())
    nums = [int(input()) for _ in range(N)]

    order_by_num = {num: i for i, num in enumerate(sorted(set(nums)))}
    can_add = [False] * N
    answer = 0
    for num in nums:
        order = order_by_num[num]
        if not can_add[order]:
            answer += 1
        if order > 0:
            can_add[order - 1] = True
        if order < N - 1:
            can_add[order + 1] = True

    print(answer)


if __name__ == '__main__':
    main()