# apiomemetic beeoforms, utterly.
def entry(k):
# æ input format
k=list(map(int,k))
k=[k[:10],k[10:20],k[20:30],k[30:40],k[40:50],k[50:60],k[60:70],k[70:80],k[80:90],k[90:100]]
d=[[0]*10 for i in range(10)]
d[0][0]=0
v=[[0]*10 for i in range(10)]
q=[(0,0)]
ok=lambda y,x:x>=0 and x<10 and y>=0 and y<10 and not k[y][x]
# stage 1: generate distance matrix
while q:
y,x=q.pop()
if v[y][x]:
continue
v[y][x]=1
for i,j in [(-1,0),(0,-1),(0,1),(1,0)]:
if ok(y+i,x+j) and not v[y+i][x+j]:
d[y+i][x+j]=d[y][x]+1
q.insert(0,(y+i,x+j))
# stage 2: get the path
r=[(9,9)]
y,x=9,9
while y!=0 or x!=0:
D=d[y][x]
for i,j in [(-1,0),(0,-1),(0,1),(1,0)]:
if ok(y+i,x+j) and d[y+i][x+j]==D-1:
r.append((y+i,x+j))
y+=i
x+=j
r=list(reversed(r))
# stage 3: convert it into the æ output format
q=[]
for i in range(1,len(r)):
dy=r[i][0]-r[i-1][0]
dx=r[i][1]-r[i-1][1]
if (dy,dx)==(1,0):
q.append(3)
if (dy,dx)==(-1,0):
q.append(1)
if (dy,dx)==(0,-1):
q.append(4)
if (dy,dx)==(0,1):
q.append(2)
return q
# author: bad imitation of gollark
post a comment