출처 : 링크텍스트
도착점에 도달하기 위해서 위에서부터 시작하기에는 경우의 수가 많다. 이를 줄이기 위해 도착점에서 위로 상승하여 출발점을 찾아내는 방법을 고안하였다.
for tc in range(1, 11):
T = int(input())
ladder = [list(map(int, input().split())) for _ in range(100)]
end = 0
for i in range(100):
if ladder[99][i] == 2:
end = i
c = end
for r in range(99, 0, -1):
if c > 0 and ladder[r][c - 1]:
while c > 0 and ladder[r][c - 1]:
c -= 1
elif c < 99 and ladder[r][c + 1]:
while c < 99 and ladder[r][c + 1]:
c += 1
print('#{0} {1}'.format(tc, c))