[20250910] PGM / LV2 / 마법의 엘리베이터 / 김수연 #861
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://school.programmers.co.kr/learn/courses/30/lessons/148653
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
마법의 엘리베이터에는 -1, +1, -10, +10,...과 같이 절댓값이 10^c 형태인 정수들이 적힌 버튼이 있음
현재 층 수에 버튼에 적혀 있는 값을 더한 층으로 이동하게 될 때,
어떤 층에서 엘리베이터를 타고 0층으로 내려가는데 필요한 버튼의 최소 개수 구하기
🔍 풀이 방법
단순 구현
현재 층 수의 마지막 자릿수를 0으로 만들어야 함
만약 마지막 자릿수가 5보다 작으면 -1을 해주는게 최소고,
5보다 크면 +1을 해주는게 최소다.
5와 같으면 한자리 앞의 수를 봐서 5보다 크거나 같으면 +1을 5번 해주는게 최소고,
한자리 앞의 수가 5보다 작으면 5보다 작으면 -1을 5번 해주는게 최소다.
⏳ 회고
뭔가 당연히 dp일거라고 생각했는데, 단순 구현이어서 당황스럽다