Submission #3044582
Source Code Expand
{-# LANGUAGE FlexibleContexts #-} import Control.Applicative import Control.Monad import Control.Monad.ST import Control.Monad.State import Data.Array.ST import Data.List import Data.Array type Node = Int type Cost = Int type Edge = (Node, Cost) type Graph = Array Node [Edge] inf = div maxBound 2 :: Int warshall_floyd :: Graph -> Array (Node,Node) Cost warshall_floyd graph = runST $ do let (s,e) = bounds graph dp <- newArray ((s,s),(e,e)) inf :: ST s (STUArray s (Node,Node) Cost) forM_ [s..e] $ \i -> do writeArray dp (i,i) 0 forM_ [s..e] $ \i -> do forM_ (graph ! i) $ \(j,c) -> do writeArray dp (i,j) c forM_ [s..e] $ \k -> do forM_ [s..e] $ \i -> do forM_ [s..e] $ \j -> do a <- readArray dp (i,j) b <- readArray dp (i,k) c <- readArray dp (k,j) writeArray dp (i,j) $ min a (b+c) freeze dp main = do (h:w:_) <- map read . words <$> getLine :: IO [Int] graph <- array (0,9) <$> (forM [0..9] $ \i -> do edges <- zip [0..9] . map read . words <$> getLine :: IO [(Int,Int)] return $ (i, edges) ) let cost = warshall_floyd graph print =<< (sum . concat . map (map ((\x -> if x == -1 then 0 else cost!(x,1)) . read) . words) . lines <$> getContents)
Submission Info
Submission Time | |
---|---|
Task | D - Wall |
User | you070707 |
Language | Haskell (GHC 7.10.3) |
Score | 400 |
Code Size | 1348 Byte |
Status | AC |
Exec Time | 196 ms |
Memory | 2428 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 128 ms | 2300 KB |
02.txt | AC | 128 ms | 2300 KB |
03.txt | AC | 106 ms | 2300 KB |
04.txt | AC | 127 ms | 2300 KB |
05.txt | AC | 72 ms | 2300 KB |
06.txt | AC | 119 ms | 2300 KB |
07.txt | AC | 128 ms | 2300 KB |
08.txt | AC | 22 ms | 1276 KB |
09.txt | AC | 22 ms | 1660 KB |
10.txt | AC | 119 ms | 2300 KB |
11.txt | AC | 127 ms | 2300 KB |
12.txt | AC | 127 ms | 2300 KB |
13.txt | AC | 196 ms | 2428 KB |
14.txt | AC | 196 ms | 2428 KB |
15.txt | AC | 2 ms | 1020 KB |
16.txt | AC | 127 ms | 2300 KB |
sample_01.txt | AC | 2 ms | 892 KB |
sample_02.txt | AC | 2 ms | 892 KB |
sample_03.txt | AC | 2 ms | 892 KB |