[20251207] BOJ / P3 / 건초 더미 / 권혁준 #1608
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/34119
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
수직선의 위치 0에서 오른쪽 방향으로 정수 크기의 힘을 가진 화살이 발사된다.
위치 1부터 N까지에는 방어력이 각각 D[i]인 건초 더미를 하나 설치할 수 있다.
화살이 건초 더미에 부딪칠 때 화살의 힘이 건초 더미의 방어력 D[i]보다 높다면 힘이 D[i]만큼 감소된 채로 관통하여 날아가고, 그렇지 않다면 멈춘다.
f(X, P) = 힘이 P인 화살이 위치 X 이하에서 멈추도록 하기 위해 설치해야 하는 건초 더미의 최소 개수라고 할 때, 이걸 Q번 구해보자.
🔍 풀이 방법
주어지는 쿼리들의 순서를 바꿔도 답을 구하는데 지장이 전혀 없으니까
오프라인 쿼리, 위치 기준 오름차순으로 처리해야겠다고 생각했다.-> 사용 가능한 건초 더미를 점점 늘려가며 쿼리 처리를 할 수 있게 된다.
건초 더미의 개수를 최소화하기 위해서는 방어력이 가장 높은 것부터 사용하는 것이 항상 최적이다.
따라서, 사용 가능한 건초 더미들 중에서 방어력이 높은 순으로 몇 개를 합쳐야 처음으로 P 이상이 되는지 확인하면 된다.
저걸 보니
이분 탐색을 굉장히 쓰고 싶게 생겼다.**K개를 합쳤을 때 P이상이 되는가?**로 문제를 바꾸고, K를 이분 탐색으로 찾아주었다.
합을 빠르게 구하기 위해서
세그먼트 트리를 사용했다.⏳ 회고
구현이 생각보다 복잡했음