[20250206] BOJ / 골드4 / A를 B로 / 신동윤 #61
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/13019
🧭 풀이 시간
60 분
👀 체감 난이도
✏️ 문제 설명
🔍 풀이 방법
머리가 안돌아가서 구글링했다 😥
A를 B로 바꿀 수 없는 경우를 판단하는 것은 쉽다.
모든 문자를 바꿔보지 않아도 된다.
A와 B의 포인터를 뒤에서부터 설정해주고 일치 여부를 확인한다.
A[A포인터] == B[B포인터]라면 일치하므로 연산을 수행하지 않고 넘어간다.A포인터--,B포인터--수행A[A포인터] != B[B포인터]라면A포인터자리에 있던 문자를 현재 자리에서 치워줘야 B 문자와 가까워지겠다. 연산을 수행한다.A포인터--수행B포인터는 그대로 두고, 다음에A포인터가 가리킬 문자는 일치하기를 바란다. 두근두근~예제 입력 5를 예로 들자면 아래와 같은 동작을 하며 최소 연산 횟수를 구한다.
일치일치불일치-> (A)DC일치불일치-> (DA)⏳ 회고