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
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
R로만 이루어진 문자열은ㅋㅋ루ㅋㅋ 문자열이다.ㅋㅋ루ㅋㅋ 문자열의 양 끝에K를 하나씩 붙인 문자열은ㅋㅋ루ㅋㅋ 문자열이다.ㅋㅋ루ㅋㅋ 문자열이 되는 경우 중 길이가 가장 긴 것을 구해보자.🔍 풀이 방법
[사용한 알고리즘]
문자열의 길이를$N$ 이라고 하자.
만약,$O(N^2)$ 에 풀어도 된다면, 두 지점 $l, r$ 을 잡아서 $[1, l]$ 와 $[r,N]$ 범위에서는
K만 골라오고, 그 사이에서는R만 골라왔을 때를 모두 구해주면 된다.특징 하나를 관찰하면, 모두 구하지 않고도 답을 알아낼 수 있다.
ㅋㅋ루ㅋㅋ 문자열의 양 끝에는 동일한 개수의K가 존재한다!그럼, 두 지점$l, r$ 을 잡을 때 굳이 $O(N^2)$ 이 아니라, 동일한 개수의 $O(N)$ 에 구현할 수 있다.
K만 가지도록 적절히 이동시키면⏳ 회고
ㅋㅋ루ㅋㅋ 문자열이 아닌데 그걸 처리하지 못해서 틀렸었다.