[20250802] BOJ / P4 / 푸앙이와 레벨업 / 권혁준 #592
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/25599
🧭 풀이 시간
50분
👀 체감 난이도
✏️ 문제 설명
N*N크기의 2차원 격자가 있고, 각 칸에는 정수 a[i][j]가 적혀있다.
칸 (i,j)에서 기술을 사용하면 (i,j) ~ (i+K-1, j+K-1) 범위의 정사각형 내에서 a의 최댓값을 찾아 그만큼 점수를 올릴 수 있다.
모든 칸에서 기술을 한 번씩 사용할 때, 점수가 R 이상이 되도록 하기 위한 K의 최솟값을 구해보자.
🔍 풀이 방법
K값이 점점 늘어날 수록, 각 점에서 기술을 사용할 때 얻는 점수는 줄어들지 않는다.
-> K를
이분 탐색으로 찾을 수 있다.각 행, 열별로 최댓값을 저장하는 배열 row, col를 정의했다.
row[i][j] = max(A[i][j] ~ A[i][j+K-1])
col[i][j] = max(A[i][j] ~ A[i+K-1][j])
이걸 빠르게 구하기 위해,
덱+슬라이딩 윈도우를 사용했다.그러면 (i, j)칸에서 얻을 수 있는 점수는 max(row[i][j] ~ row[i+K-1][j], col[i][j] ~ col[i][j+K-1]) 이 된다.
이것도 덱 + 슬라이딩 윈도우로 똑같이 구할 수 있다.
구한 점수가 R 이하인지에 따라 이분 탐색의 범위를 좁혀주었다.
⏳ 회고
덱 너무 어렵다