[20260206] BOJ / P3 / 삶의 질 / 권혁준 #1893
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/10227
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
R$\times$ C크기의 격자판 각 칸에 1부터 R $\times$ C까지의 수가 중복 없이 채워져있다.
이 격자판에서 모든 H*W크기의 부분 격자판의 중앙값 중 최솟값을 구해보자.
🔍 풀이 방법
문제를 이렇게 바꿔봤다.
x이하의 수만 사용했을 때 중앙값이 x이하인 수가 존재하는가?각 칸에 x이하인 수가 있으면 1, 아니면 0으로 설정해놓고 2차원 누적 합을 돌린다.
여기서 어떤 H*W 범위에 절반 이상의 수가 존재하는지 구하면 해결할 수 있다.
위 문제의 답은 x가 0일 때는 NO이고, x가 점점 증가하면서 어느 순간 YES로 바뀐다.
이 x를 찾으면 그게 중앙값 중 최소가 된다.
그래서 x를 이분 탐색으로 찾아줬다.
⏳ 회고
처음 봤을 때는 2차원 부분 직사각형에 대한 문제길래, 당연히 덱 DP겠구나 싶었는데 도저히 풀이가 안 떠올라서 다른 방법을 생각해보게 됐다.