기출 문제 / 삼성 2024 First Half Afternoon Problem 1

Exploration of the Magical Forest

The spirits are attempting to explore a magical forest arranged in a grid of R rows and C columns. The grid is numbered from the top as row 1 to the bottom as row R.

The east, west, and south sides of the forest are blocked by magical walls, and the spirits can only enter the forest from the north.