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/20442
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
K와 R로 이루어진 문자열에서 부분수열 중 가장 긴 "ㅋㅋ루ㅋㅋ" 문자열 찾기
ㅋㅋ루ㅋㅋ =
K^n + R^m + K^n(양쪽 K 개수 동일)문자열 길이 최대 300만
🔍 풀이 방법
투 포인터 + 누적합
각 R 위치마다 왼쪽 K의 누적 개수 저장
오른쪽 K는 전체 K - 왼쪽 누적 K로 계산
R 구간을 양쪽에서 좁혀가며 최대값 갱신
답 = min(왼쪽K, 오른쪽K) * 2 + R개수
K가 적은 쪽 포인터 이동
시간복잡도:$O(n)$
⏳ 회고
처음엔 백트래킹 생각했지만 300만 글자라 불가능. 부분수열 문제지만 특정 패턴을 찾는 거라 투 포인터로 접근 가능했다. 누적합 없이 직전 K만 세서 틀렸고, "전체 왼쪽 K"를 누적해야 한다는 걸 깨달음. R 개수를 답에 더하는 것도 놓쳤었음.