[20260303] BOJ / G4 / 도서관 / 이준희#1989
Merged
ShinHeeEul merged 1 commit intomainfrom Mar 3, 2026
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/1461
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
0에 위치한 세준이가 도서를 정리하려고 합니다.
도서의 위치는 절대값이 10000 이하인 정수이고 한번에 M권의 책을 들고 이동할 수 있습니다.
N권의 책을 모두 정리하는 데 세준이가 최소한으로 이동할 때의 이동거리를 구하는 문제입니다.
단, 마지막 책을 정리 했을 때는 다시 0으로 돌아오지 않아도 됩니다.
🔍 풀이 방법
배열을 정렬한 후
for문을 2개 이용하여 음수 방향으로 이동하는 것과
양수 방향으로 이동하는 것에 대해 구현했습니다.
처음 책의 위치를 받을 때 미리 절대값이 가장 큰 곳에 대해 찾아서
가장 멀리 가는 경우를 돌아오지 않을 수 있도록 하였습니다.
⏳ 회고
처음에는 그냥 단순하게 배열을 정리하고
M만큼 건너뛰면서 체크하려 했는데 양수와, 음수에 대해서 따로 처리해야된다는 것을 깨달았습니다.