나의 풀이
import sys
def _main(ct, n_list):
answer = [1] * ct
answer_re = [1] * ct
n_list_re = n_list[::-1]
for idx in range(ct):
for j_idx in range(idx):
if (n_list[idx] > n_list[j_idx]):
answer[idx] = max(answer[idx], answer[j_idx] + 1)
if (n_list_re[idx] > n_list_re[j_idx]):
answer_re[idx] = max(answer_re[idx], answer_re[j_idx] + 1)
answer_re = answer_re[::-1]
result = 0
for idx in range(ct):
result = max(result, answer[idx] + answer_re[idx])
return (result - 1)
ct = int(sys.stdin.readline())
n_list = list(map(int, sys.stdin.readline().rstrip().split()))
print(_main(ct, n_list))
시간 복잡도
for idx in range(ct) : 수열 길이 만큼 순회 ( 선형 시간 복잡도 )
for j_idx in range(idx) : 현재 index 기준 앞에 수열까지 순회 ( 선형 시간 복잡도 )
해당 알고리즘 시간 복잡도 : 이차형 시간 복잡도 ( O(n ** 2) )'코딩테스트 파이썬 > 백준' 카테고리의 다른 글
| 연구소 ( 14502번 ) (0) | 2025.02.11 |
|---|---|
| 미세먼지 안녕! ( 17144번 ) (0) | 2025.02.09 |
| 평범한 배낭 (12865 번) (0) | 2025.02.01 |
| 내려가기 ( 2096번 ) (1) | 2025.01.24 |
| 최소비용 구하기 ( 1916 ) (0) | 2025.01.20 |