[Gold II] Title: 가장 긴 증가하는 부분 수열 2, Time: 756 ms, Memory: 134932 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-03-30 15:30:10 +09:00
parent 12f8a9da9e
commit 29dcc343f7
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# [Gold II] 가장 긴 증가하는 부분 수열 2 - 12015
[문제 링크](https://www.acmicpc.net/problem/12015)
### 성능 요약
메모리: 134932 KB, 시간: 756 ms
### 분류
이분 탐색, 가장 긴 증가하는 부분 수열: O(n log n)
### 제출 일자
2025년 3월 30일 15:28:59
### 문제 설명
<p>수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오.</p>
<p>예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {<strong>10</strong>, <strong>20</strong>, 10, <strong>30</strong>, 20, <strong>50</strong>} 이고, 길이는 4이다.</p>
### 입력
<p>첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000,000)이 주어진다.</p>
<p>둘째 줄에는 수열 A를 이루고 있는 A<sub>i</sub>가 주어진다. (1 ≤ A<sub>i</sub> ≤ 1,000,000)</p>
### 출력
<p>첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다.</p>

View File

@@ -0,0 +1,17 @@
from bisect import bisect_left
import sys
input = sys.stdin.readline
n = int(input())
lst = list(map(int, input().split()))
stack = []
for i in lst:
if not stack or stack[-1] < i:
stack.append(i)
else:
a = bisect_left(stack, i)
stack[a] = i
print(len(stack))