[20251123] BOJ / D5 / Hangar Hurdles / 권혁준 #1490
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/13952
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
빈 칸과 벽으로 이루어진 N*N크기의 2차원 격자가 있다.
한 변의 길이가 홀수 K인 정사각형 모양을 상자라고 부르며, 격자 칸에 맞게 배치할 수 있다.
상자는 벽에 부딪히지 않는다면 상하좌우로 이동할 수 있다.
아래 질문을 Q번 처리하기.
🔍 풀이 방법
1차원 좌표로 압축, 칸 (i,j)의 1차원 번호는 i*N+j로 치환
cost[x] = x번 점에 놓을 수 있는 상자의 최대 크기라고 정의
격자의 벽의 개수를 2차원 누적 합으로 관리하면 cost[x]는
누적 합+이분 탐색으로 O(log^2(N))에 구할 수 있다.-> 모든 cost를 구하면 O(N^2log^2(N))
각 점에서 4방향 이동이 가능한데, 점 x에서 y로 이동한다고 했을 때 간선의 가중치는 min(cost[x], cost[y])
간선 가중치가 큰 것부터
분리 집합으로 합쳐주며최소 스패닝 트리를 구성 (크루스칼)만들어진 트리에서
희소 배열을 이용해 경로 쿼리를 지원하도록 구현했다.쿼리 처리할 때는 두 점 사이의 최소 가중치로 구하기
⏳ 회고