[20250924] BOJ / G5 / Sunny Days / 권혁준 #966
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/34457
🧭 풀이 시간
10분
👀 체감 난이도
✏️ 문제 설명
'S'랑 'P'만으로 이루어진 수열이 있다.
원소 하나를 무조건 반대로 바꿔야 할 때, 연속된 'S'의 개수의 최댓값을 구해보자.
🔍 풀이 방법
l[i], r[i]를 정의해서 각각 왼쪽, 오른쪽에서부터 i번째 원소까지 연속된 'S'의 개수로 관리한다.
누적 합으로 둘 다 구해줬고, 답을 구할 때는 i번째 원소가 바뀐 경우를 생각한다.
i번째 원소가 'P'인 경우에는 연속된 'S'의 개수가 l[i-1] + r[i+1] + 1이고,
반대인 경우에는 max(l[i-1], r[i+1])개가 된다.
⏳ 회고
다른 풀이로 빠지기 쉬운듯