[20251105] BOJ / P4 / 방어선 / 권혁준 #1319
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/3429
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
길이 N인 수열에서 임의의 연속한 구간 하나를 지웠을 때, 가장 긴 연속하는 증가 부분 수열의 길이를 구해보자.
🔍 풀이 방법
cnt[i] = i번째 원소 a[i]를 마지막으로 하는 가장 긴 연속 증가 부분 수열의 길이
(a[i], i) 리스트 만들어놓고 a[i]의 오름차순대로 (a[i], i) 쌍을 하나씩 처리
-> cnt2[i] = max(cnt[1], ..., cnt[i-1]) + 1
이걸로 연속한 구간 하나를 날려버리는 작업은 끝
연속한 구간을 날린 후에 증가 부분 수열이 뒤로 더 생길 수 있으니까
cnt2에서 한 번 돌면서 a[i-1] < a[i]인 i에 대해 cnt2[i] = max(cnt2[i], cnt2[i-1] + 1) 수행
답은 max(cnt2)로 구함.
⏳ 회고
생각보다 까다로움