Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/1981
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
n×n 크기의 격자에서 (1,1)에서 (n,n)까지 상하좌우로만 이동할 수 있음, 이동 경로에서 만나는 숫자들 중
최댓값과 최솟값의 차이가 최소가 되는 경로를 찾아 그 차이값을 출력
🔍 풀이 방법
이진 탐색을 활용하여 "최댓값-최솟값의 차이"를 찾음. 이 차이를 mid로 두고, 해당 차이로 도착지점까지 도달할 수 있는지 확인
배열의 최솟값부터 시작해서 [min, min+diff] 범위 내의 숫자들만 사용하여
BFS로 (0,0)에서 (N-1,N-1)까지 도달할 수 있는지를 확인
도달할 수 있다면 더 작은 차이값도 가능한지 탐색하고, 불가능하다면 더 큰 차이값을 확인
도달하지 않는 경우는 없음
⏳ 회고
처음에는 dfs 백트래킹 사용해서 확인하려 했지만 시간초과 날거같아서 안함.
단순 bfs로 한번에 하려 하니 방문관리도 어렵고 경로가 직관적이지 않았음 -> 불가능한듯..?
가능한 diff에 대해서 모두 bfs를 돌리기에는 시간초과 날거 같았음
문제 알고리즘 유형에 이진 탐색이 있어 확인하고 해결
이런식으로 최적화 문제를 결정 문제로 바꿔서 해결하는걸 파라매트릭 서치.. 라고 한다네요?