[20251004] BOJ / G4 / 전구와 스위치 / 이강현 #1035
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/2138
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
전구마다 버튼이 있음.
특정 위치의 버튼을 눌렀을때, 해당 위치의 전구와 양옆 전구가 반전됨.
현재 전구의 상태와 목표 상태가 주어졌을때, 목표 상태로 가기위해 최소로 버튼을 누르는 횟수를 구하기.
🔍 풀이 방법
그리디
특정 전구가 특정 버튼에만 상태를 의존하게끔 만들기.
첫번째 전구는 자신의 버튼과 두번째 버튼에만 상태가 의존됨.
두번째 전구도 마찬가지로 두번째 버튼을 누르거나 안누른 상태가 되면 세번째 버튼에만 상태가 의존됨.
따라서 첫번재 버튼은 누른 경우와 누르지 않은 경우로 나누고
이동하면서 전구의 상태가 목표 상태와 다르다면 눌러주면 됨.
⏳ 회고
상태가 복잡하다면 어느 하나를 고정하여 생각하자.