Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Sep 24, 2025

🧷 문제 링크

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])개가 된다.

⏳ 회고

다른 풀이로 빠지기 쉬운듯

@oncsr oncsr self-assigned this Sep 24, 2025
@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Sep 24, 2025
@ShinHeeEul ShinHeeEul merged commit e8915e5 into main Sep 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants