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/2939
🧭 풀이 시간
300+ 분
👀 체감 난이도
✏️ 문제 설명
R행 C열의 격자 그래프가 있다. 각 칸은 A[r][c]의 가중치를 가진다.
어떤 칸이 만약 1열 혹은 C열이라면, 위아래로만 이동할 수 있다.
그렇지 않다면, 양옆으로만 이동할 수 있다.
이 그래프에서 D개의 점을 순서대로 지날 때 최단 경로를 구해보자.
🔍 풀이 방법
어떤 칸 A에서 다른 칸 B로 가는 최단 경로는 네 가지 경우밖에 없다고 생각했다.
위 네 가지 경우를 빠르게 찾아내기 위해서, (i,1)와 (j,C)를 잇는 최단 경로를 빠르게 구할 수 있어야 한다.
이때 최소 하나 이상의 행을 가로질러야 한다. 가로지르는 행의 위치에 따라서 세 가지 dp로 나누었다. (up[i][j], mid[i][j], down[i][j])
특별히, 1열과 C열에서의 최단 경로는 각각 left, right 배열에 누적 합으로 구해줬다.
근데 이렇게 설계하고 제출했더니 틀렸다
⏳ 회고
아마 left, right를 단순히 누적 합으로 구하면 안되는 것 같다.
같은 열에서의 이동도 행을 가로질러야 최단 거리가 되는 경우가 있기 때문이다.
내일 다시 고민해봐야겠음