생성일: 2022년 2월 19일 오후 4:39
# 사다리 타기 (DFS)
import sys
sys.stdin = open("input.txt", "rt")
def DFS(L, x, y):
if x == 9:
if board[x][y] == 2:
print(L)
sys.exit()
else:
if 0<=y-1<10 and board[x][y-1] == 1:
board[x][y] = 0
DFS(L, x, y-1)
board[x][y] = 1
elif 0<=y+1<10 and board[x][y+1] == 1:
board[x][y] = 0
DFS(L, x, y+1)
board[x][y] = 1
else:
board[x][y] = 0
DFS(L, x+1, y)
board[x][y] = 1
if __name__ == "__main__":
board = []
for _ in range(10):
board.append(list(map(int, input().split())))
people = [0, 2, 5, 7, 9]
for x in people:
DFS(x, 0, x)
import sys
sys.stdin=open("input.txt", "r")
def DFS(x, y):
ch[x][y]=1
if x==0:
print(y)
else:
if y-1>=0 and board[x][y-1]==1 and ch[x][y-1]==0:
DFS(x, y-1)
elif y+1<10 and board[x][y+1]==1 and ch[x][y+1]==0:
DFS(x, y+1)
else:
DFS(x-1, y)
board=[list(map(int, input().split())) for _ in range(10)]
ch=[[0]*10 for _ in range(10)]
for y in range(10):
if board[9][y]==2:
DFS(9, y)