251203 : [BOJ 1461] 도서관 - #2220
Merged
Merged
Conversation
sunha20
requested review from
3veryDay,
KII1ua and
dlchdaud123
as code owners
December 2, 2025 23:12
Closed
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.
🚀 이슈 번호
Resolve: {#2219}
🧩 문제 해결
스스로 해결: ✅(40m)
🔎 접근 과정
접근: 최단경로라길래 그래프나 DP(M값 기준)를 잠시 고려했는데 좌표가 1차원 선상에 있고. 딱히 기존 값을 참고해서 값이 변하는 것도 아니라서 그리디를 고려. 가장 먼 책들부터 처리하는 방식이 최적해를 보장 해서 그리디로 해결했습니다.
풀이: 마지막을 제외하고는 0에서 출발해서 0으로 돌아와야하기 때문에 좌표를 음수/양수로 나누어 리스트에 저장. 마지막은 돌아오지 않기 때문에 가장 먼 좌표를 선택해서 따로 편도 처리하고 나머지 이동을 처리.
⏱️ 시간 복잡도
O(nlogn)리스트에 저장: O(N)
리스트 정렬: O(NlogN)
리스트 순회/계산: O(N/M)
N이 50이기 때문에 O(NlogN)도 충분함
💻 구현 코드