[20250711] BOJ / G3 / 공주님의 정원 / 이강현 #440
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/2457
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
공주님은 3월 1일부터 11월 30일 사이에 정원에 꽃이 피어있으면 좋겠다고 생각함.
근데 정원이 작아서 꽃이 최소 하나라도 피어있으면 정원에 피어있다고 하기로 함.
꽃이 피고 지는 월 일이 각각 주어질때, 공주님을 만족시키는데 필요한 꽃의 개수를 출력.
🔍 풀이 방법
정렬, 그리디
꽃이 피는 시기를 기준으로 정렬하고 같다면 지는 시기를 기준으로 정렬함.
꽃들을 순회하며 새로운 꽃이 이전의 꽃들이 통해 커버를 시작한 날짜보다 피는 시간이 이르고
커버를 끝내는 날짜보다 지는 시간이 느릴때, 이를 저장해둠.
만약 꽃이 커버를 시작한 날짜보다 늦게 핀다면, 이전에 가장 넓게 커버할 수 있는 꽃을 등록하고 그 꽃이 지는 시간을
현 시점에서 가장 많이 커버할 수 있는 날짜로 업데이트 함.
11월 30일까지 커버할 수 있는 경우 플래그를 세팅하고 종료
⏳ 회고
정렬을 어떻게 해두면 좋을까 생각해서 어려웠는데 사실 정렬은 별거 없고
꽃 정보를 적절히 저장하고 앞에서부터 차근차근 등록하면 되는거였음.
구현이 어렵진 않지만 생각하는 과정에서 많이 헷갈렸던 것 같다.