結果

問題 No.1 道のショートカット
ユーザー kroton
提出日時 2015-06-05 20:20:11
言語 Haskell
(9.10.1)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 956 bytes
コンパイル時間 8,504 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-07-20 16:14:49
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Data.List

main = do
    n <- read <$> getLine
    c <- read <$> getLine
    getLine
    s <- map read . words <$> getLine
    t <- map read . words <$> getLine
    y <- map read . words <$> getLine
    m <- map read . words <$> getLine
    print $ solve n c $ createRouteList s t y m

inf :: Int
inf = 2^20

solve :: Int -> Int -> [Route] -> Int
solve n cmax routes = if ans < inf then ans else -1
    where
        ans = f 1 cmax
        f m c | m == n = 0
              | otherwise = foldr min inf [(memo !! ((to r) - 1) !! (c - (cost r))) + (rtime r) | r <- es]
            where
                es = [r | r <- routes, (from r) == m, c - (cost r) >= 0]
        memo = [[f m c | c <- [0..cmax]] | m <- [1..n]]

data Route = Route
    { from :: Int
    , to :: Int
    , cost :: Int
    , rtime :: Int
    } deriving (Show)

createRouteList :: [Int] -> [Int] -> [Int] -> [Int] -> [Route]
createRouteList = zipWith4 Route
0