[20260105] BOJ / G2 / 오타 / 한종욱 #1772
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/5875
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
오타를 냈다. 한 문자만 고쳐서 올바른 괄호쌍이 될 수 있는 경우의 수를 출력하라.
🔍 풀이 방법
문제에선 '('가 ')'보다 2개 많거나, ')'가 '('보다 2개 많은 경우만 주어진다.
둘 중 어떤 것을 고쳐야 하는지 한번 계산한다.
그 다음, ')'가 더 많은 걸 기준으로 설명하겠다.
'('는 1, ')'는 -1로 계산해서 누적합을 계산하고 처음 -1이 될 때, 그 앞의 ')'의 개수를 센다.
⏳ 회고
처음엔 -2가 되는 순간 그 한 칸 앞들인 줄 알았다. 근데 이건 괄호쌍이기 때문에, 합이 0인 것도 중요하지만 누적합이 음수가 되지 않아야 한다는 걸 인지하지 못하고 있었다. g선생이 알려주지 않았다면 계속 틀렸을 것이다.