[20250225] BOJ / P5 / 부분배열 고르기 / 신희을 #178
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/2104
🧭 풀이 시간
120 분
👀 체감 난이도
✏️ 문제 설명
크기가 N(1 ≤ N ≤ 100,000)인 1차원 배열 A[1], …, A[N]이 있다. 어떤 i, j(1 ≤ i ≤ j ≤ N)에 대한 점수는, (A[i] + … + A[j]) × min{A[i], …, A[j]}가 된다. 즉, i부터 j까지의 합에 i부터 j까지의 최솟값을 곱한 것이 점수가 된다.
배열이 주어졌을 때, 최대의 점수를 갖는 부분배열을 골라내는 프로그램을 작성하시오.
🔍 풀이 방법
세그 트리에 최솟값과 최솟값을 갖는 인덱스를 함께 저장한다.
최솟값을 갖는 인덱스를 기준으로 구간을 분할하고, 해당 구간의 넓이를 계산한다.
해당 구간을 기준으로 다시 최솟값을 찾는 로직을 반복한다.
⏳ 회고
히스토그램이랑 같은 문젠데, 히스토그램 때도 못풀어서 해설 봤었는데 이번에도 보게 되었다.. 세그 트리에 업데이트 기준과 안의 값을 다르게 할 수 있음도 항시 염두해두자!