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/42586
💡 풀이 아이디어
이 문제는 progresses 들이 큐 처럼 선입선출로 배포되어야 한다는 규칙이 있습니다.
따라서 가장 먼저 배포되는 작업이 걸리는 작업 일자가 필요하고, 이후 순차적으로 각 작업이 가장 먼저 배포되는 작업의 작업 일자보다 작거나 같으면 함께 배포됩니다.
실제로 progresses를 큐처럼 관리하여 맨 처음 작업을 배열에서 제거할 수도 있겠지만 시간이 오래 걸리는 작업일 것 같아 하지 않았고 배열을 탐색하면서 처리해주었습니다.
처음에 작업 일자를 구할 때에는 아래와 같이 작성했었는데, 테스트 케이스 중 2번, 11번이 실패하였습니다.
0.5를 더해준 이유는 올림 연산을 하기 위해서 사용하였습니다.
실패한 이유가 실수 연산에 대한 오차때문인 것 같아 코드를 수정해주니 모든 테스트 케이스를 통과하였습니다.
divmod(a, b)
는(a // b, a % b)
을 튜플로 반환하는 함수로 가독성이 좋아 편해서 사용하는데 확인해보니 작은 숫자를 다룰 때는a//b, a%b
와 같이 풀어서 쓰는게 성능 면에서 더 좋다고 합니다.📝 새로 학습한 내용
작업 일자를 계산할 때 올림 연산을 하지 않기 위해 음수로 몫을 구하는 방식이 아주 인상깊었습니다..! 🫢
다른 사람의 풀이
📚 참고 자료