Problem 81(Dijkstra)

Dijkstraで解く。

import Dijkstra
import Data.Graph
import Data.Array.IArray
w = 80
xi (i,j) = w*i+j
mkGraph = buildG (,w*w).((w*w,):).concatMap e$range b
where b = ((,),(w-1,w-1))
e (i,j) = [(xi (i,j),xi x)|x<-[(i+1,j),(i,j+1)],inRange b x]
mkWeight a = array b .(s:).concatMap e $range b'::Weight
where b = ((,),(w*w,w*w))
b' = ((,),(w-1,w-1))
e (i,j) = [((xi (i,j),xi x),a!x)|x<-[(i+1,j),(i,j+1)],inRange b' x]
s = ((w*w,),a!(,))
mkArray ::String->Array (Int,Int) Int
mkArray ws= listArray ((,),(w-1,w-1)) ws'
where ws'=concat.map (read.g).lines$ws
g x = "["++x++"]"
main =do
f<-readFile "matrix.txt"
print.fst.shortestPath mkGraph (mkWeight$mkArray f) (w*w) $w*w-1

DPのほうが速かった件について

More Reading
Newer// Problem 91
Older// Problem 82