나의 풀이
1. 실패.. 왜 실패했는지 모르겠다ㅠ 오류는 안나는데 값이 안 맞음
n, m = map(int, input().split())
graph = [list(map(int, input())) for _ in range(n)]
x, y = (1, 1)
dir = [(0, 1), (1, 0), (-1, 0), (0, -1)]
result = 1
for go in range(n * m):
for i in range(4):
new_x = x + dir[i][0]
new_y = y + dir[i][1]
if graph[x][y] == (n, m):
break
if graph[new_x][new_y] == 0 or new_x < 0 or new_x >= n or new_y < 0 or new_y >= m:
continue
if graph[new_x][new_y] == 2:
x = new_x
y = new_y
if graph[new_x][new_y] == 1:
graph[x][y] = 2
x = new_x
y = new_y
result += 1
print(result)