[20250710] BOJ / G2 / 벽 부수고 이동하기 4 / 이강현 #432
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/16946
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
M x N의 공간에서 벽은 1, 빈 공간은 0임.
모든 벽에서 갈 수 있는 칸의 수를 구하고 이를 출력.
🔍 풀이 방법
BFS
0이 모여있는 공간을 대표하는 i,j 값을 설정하고 나머지 i,j들은 대표하는 i,j를 가리키도록 하는 맵 하나와
공간의 대표 i,j로 저장된 그 내부의 0들의 수를 저장하는 맵을 사용함.
모든 1을 순회하며 상하좌우에서 뭉쳐있는 0들과 인접한 경우 그 공간에 있는 0들의 값을 더해줌.
⏳ 회고
벽에서 이동할 수 있는 칸을 10으로 나눈 나머지를 출력해야하는데, 이걸 단순히 모듈러 연산하면
순회하면서 0일때 들어가는 조건문과 겹치게 됨.
최대 1000x1000이므로 하나의 벽이 가질 수 있는 최대값은 int 변수에 충분히 담을 수 있으므로 모듈러 연산은 마지막 출력때 진행해야함.