[20260108] BOJ / P5 / 안대 낀 스피드러너 / 이강현 #1778
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/14451
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
러너가 왼쪽 맨 아래에서 오른쪽 맨 위로 이동할거임.
러너는 직진, 우회전, 좌회전 세가지 행동이 가능함.
초기 러너는 어디를 바라볼지 모름. 하지만 위 또는 오른쪽 둘 중 하나임.
어떻게 있든 같은 명령어 시퀀스로 도착지에 도착할때, 최소 행동으로 도착하도록 해야함.
이때 명령어 횟수를 출력.
🔍 풀이 방법
BFS
상태 자체를 위를 바라보고 시작하는 경우와 오른쪽을 바라보고 시작하는 경우로 정의함.
이후 상태에 따라 직진, 좌회전, 우회전을 실시하며 두 경우 모두 도착지로 도착했을때, 그때의 step을 출력
⏳ 회고
위를 바라보든 오른쪽을 바라보든 상관없다고 처음에 생각했다.
위를 바라보면서 우회전을 하는 경우와 오른쪽을 바라보면서 좌회전을 하는경우에 둘다 같은 명령어 횟수로 도달 가능했기 때문이었다.
그래서 위치와 방향만 상태에 저장하고 둘다 큐에 넣어두는 방식으로 구현했었다.
하지만 핵심은 어떤 상태이든지 같은 명령어를 따르기만하면 도착지에 도착해야한다는 것이 핵심이었다.
따라서 두 경우를 하나의 상태로 합쳐서 이동해야했다.
그리고 두 경우중 하나가 미리 도착하면 컷신이 발동해서 명령에 영향을 받지 않는다는 것을 간과했는데, 이를 처리하여 풀 수 있었다.