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/1114
🧭 풀이 시간
3일
👀 체감 난이도
✏️ 문제 설명
통나무의 길이, 자를 수 있는 위치와 자를 수 있는 횟수가 주어진다. 분할된 통나무의 최대 길이가 가장 작게 분할했을 때, 최대 길이와 가장 먼저 분할한 위치를 구하자.
🔍 풀이 방법
이분 탐색
⏳ 회고
공유기 설치 문제와 비슷한 느낌의 이분 탐색, 다만 공유기 설치는 공유기 각각의 위치를 최대한 넓게 하기만 하면 되었기에 먼저 맨 앞에 설치해놓고 그냥 mid값 조정하면서 횟수만 맞추면 됐음. 근데 이건 분할하는 지점이 중간에 주어져서 통나무 양 끝도 고려해야 함.
분할 횟수가 5면 조각이 6개 나올 수 있으니 여기서부터 머리 아픔. 그리고 단순히 mid 넘기면 여기서 분할하자. 이것도 아님.
분할 지점 순회하면서 mid를 넘으면 넘은 시점에서 분할할 지 바로 이전 부분에서 분할할지 결정해야 함.
안 그러면 1 6 7 8 9 일때, mid가 2고 분할 가능 횟수가 3이라고 가정하면 1에서는 안 자르고 6에서 자르고 8에서 자르게 될텐데 분할 횟수가 적어서 mid를 1로 줄이고 이분탐색을 다시 돌면 또 분할 횟수가 3을 넘어버려서 결국 mid를 2로 결정하게 됨.
이때 최댓값을 1에서 못 잘라서 6으로 반환하게 되는데 사실 1에서 자르고 6에서도 자르는게 최적임. 하고 싶은 말은 mid가 분할 기준인거지 딱 떨어지는 최적값이 아닌거임. 그냥 여기서 개빡침.
그래서 매 순간 현 시점에서 자를지 바로 이전 시점에서 자를지 생각해야하고 이전 시점에서 자르게 되면 분할되는 토막이 두개 생겨서 두개로 최댓값을 또 뽑아야함.
근데 여기서 또 끝이 아님. 자른 경우의 맨 첫번째 분할지점을 또 반환하래 그래서 뒤에서부터 잘랐음.
근데 또 분할했을 때 분할 개수가 모자르면 더 앞부분을 쪼개서 반환해야함.
1 2 5 10 에서 3번 쪼갤 수 있는데 5랑 10을 쪼개서 1번 횟수가 남았다고 하면 앞에서부터 또 안 쪼갠 부분 무의미하게 쪼개야하는거임.
너무 열받는데 내가 멍청해서 그럼 그냥