結果

問題 No.1 道のショートカット
コンテスト
ユーザー kroton
提出日時 2015-06-05 20:20:11
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 956 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,346 ms
コンパイル使用メモリ 193,280 KB
実行使用メモリ 199,332 KB
最終ジャッジ日時 2026-04-03 01:17:46
合計ジャッジ時間 3,258 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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