[20250912] BOJ / P5 / 히스토그램 / 이종환 #873
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/1725
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
히스토그램의 내부에 가장 넓이가 큰 직사각형을 그리려고 한다. 이 직사각형의 밑변은 항상 히스토그램의 아랫변에 평행하게 그려져야 한다.
첫 행에는 N (1 ≤ N ≤ 100,000) 이 주어진다. N은 히스토그램의 가로 칸의 수이다. 다음 N 행에 걸쳐 각 칸의 높이가 왼쪽에서부터 차례대로 주어진다. 각 칸의 높이는 1,000,000,000보다 작거나 같은 자연수 또는 0이다.
🔍 풀이 방법
다양한 방법을 시도해봤는데, 다 실패했다.
결국 힌트에서 분할정복이라는 것을 보고 , 지금의 로직을 떠올렸다.
s부터 e 까지 범위에서 가장 큰 직사각형의 크기를 f(s,e)라 해보자.
mid = (s+e)/2일때,
f(s,e)는 f(s,mid) , f(mid+1, e), 그리고 mid,mid+1칸을 포함하는 직사각형들중 가장 큰 값을 구하면 된다.
⏳ 회고
세그먼트라는 힌트때문에 오히려 시간을 더 썼다. 논리상으로는 들어가긴 하지만...