[20250715] BOJ / G1 / 놀이 공원 / 이종환 #471
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/1561
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
N명의 아이들이 한 줄로 줄을 서서 놀이공원에서 1인승 놀이기구를 기다리고 있다. 이 놀이공원에는 총 M종류의 1인승 놀이기구가 있으며, 1번부터 M번까지 번호가 매겨져 있다.
모든 놀이기구는 각각 운행 시간이 정해져 있어서, 운행 시간이 지나면 탑승하고 있던 아이는 내리게 된다. 놀이 기구가 비어 있으면 현재 줄에서 가장 앞에 서 있는 아이가 빈 놀이기구에 탑승한다. 만일 여러 개의 놀이기구가 동시에 비어 있으면, 더 작은 번호가 적혀 있는 놀이기구를 먼저 탑승한다고 한다.
놀이기구가 모두 비어 있는 상태에서 첫 번째 아이가 놀이기구에 탑승한다고 할 때, 줄의 마지막 아이가 타게 되는 놀이기구의 번호를 구하는 프로그램을 작성하시오.
🔍 풀이 방법
우선 입력값이 굉장히 크기에 시간대로 O(N)으로 접근하면 절대로 풀 수 없기에 이분탐색으로 접근하였다.
그런데 예외처리하는 케이스 자체를 이해하는 데 시간이 좀 걸려서 고생을 했다.
-> 조건을 만족하는 최소 소요 시간에서도 N명보다 많은 인원의 아이들이 놀이기구를 탈 수 있는 경우
또한 그 이후에도 계속 틀리기에 고민해보니, 소요 시간 자체가 Int 범위를 넘을 수 있어 long으로 변환하니 이제서야 맞았다
⏳ 회고
대충 풀지말자...