[20251115] BOJ / G1 / 난민 / 이강현 #1414
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/23090
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
난민촌들을 위한 정수시설을 지을거임..
정수시설은 x=0 그래프 위에 있음.
난민촌 N개가 순서대로 들어옴.
매 순서마다 모든 난민촌들의 정수시설까지 유클리드 거리가 최소가 되는 지점에 지을거임.
이때 정수시설의 y좌표와 거리 합을 같이 출력.
🔍 풀이 방법
우선순위큐
중앙값이 최소임. 우선순위 큐 두개로 구현
최소 힙과 최대 힙이 가지는 각각의 원소들은 개수가 같거나 최대힙이 하나 더 많음.
그니까 현재 짝수 개의 난민촌이 있으면, 힙의 개수 균형이 맞는 상태이니, 현재 난민촌을 추가하고 중앙값을 구하면 작은쪽과 큰쪽에서 오는 거리가 상쇄될거임. 그래서 현재 중앙값까지의 현재 추가된 난민촌의 거리를 더하면 됨.
홀수 개의 난민촌이 있는 경우는 최대 힙이 하나 더 많음. 따라서 중앙값이 변할때, 상쇄가 안됨. 그니까 일단 난민촌을 이전 중앙값까지의 거리로 추가하고 중앙값을 바꾸면 개수가 맞아져서 상쇄됨.
⏳ 회고
잘 구현해놓고 중앙값 구하는 로직을 잘못구해서 시간 개많이썼네 에효