Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
No heap solution in Clear category for Digging a Canal by DiZ
from bisect import insort
#Dijkstra's algorithm
#Bag is always sorted, thanks to insertion in place.
def checkio(land):
m, n, visited = len(land), len(land[0]), set()
bag = sorted((start, 0,i) for i, start in enumerate(land[0]))
while bag:
digged, x,y = bag.pop(0)
visited.add((x,y))
if x == m-1: return digged
for i,j in [(1,0),(0,1),(0,-1),(-1,0)]:
xn, yn = x+i, y+j
if not (0<=xn
Aug. 27, 2014