[20250810] BOJ / P4 / 무자비한 최단 경로 / 권혁준#642
Merged
ShinHeeEul merged 1 commit intomainfrom Aug 10, 2025
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/25500
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
3차원 공간에 N개의 점이 있다.
두 점 i, j 사이에는 가중치가 min(|x[i]-x[j]|, |y[i]-y[j]|)인 간선이 존재한다.
또, z[i] + z[j]가 K로 나누어 떨어지면, 가중치가 z[i] + z[j]인 간선도 존재한다.
1번 점에서 출발했을 때, 각 점까지의 최단 거리를 모두 구해보자.
🔍 풀이 방법
x, y좌표에 대해 간선을 생성하는 건 행성 터널 문제랑 똑같다.
z축에 대한 간선 처리는 mod K가 같은 것들끼리 리스트를 만들어서 관리했는데, 시간 초과가 발생했다.
다익스트라에서 어떤 점을 pq에서 꺼내어 거리 비교 후 살아남은 점들은 최단 거리가 확정된 것이라는 발상으로부터, 고를 수 있는 z축 간선의 개수를 줄여줬는데도 시간 초과를 피하지 못했다.
그렇다고 x, y축처럼 가장 짧은 것 하나만 보는 건 반례가 있어서 안 된다.
z축 처리를 어떻게 해줘야할 지 모르겠다.
⏳ 회고
개어려움