結果

問題 No.1 道のショートカット
ユーザー らっしー(raccy)
提出日時 2015-06-05 19:42:17
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 1,631 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 172,416 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-07-08 04:04:38
合計ジャッジ時間 2,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 6 WA * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Data.Maybe
import Data.List
import Control.Applicative

main :: IO ()
main = do
    n <- read <$> getLine
    c <- read <$> getLine
    v <- read <$> getLine
    s <- map read . words <$> getLine
    t <- map read . words <$> getLine
    y <- map read . words <$> getLine
    m <- map read . words <$> getLine
    print $ no1 n c v s t y m

no1 :: Int -> Int -> Int -> [Int] -> [Int] -> [Int] -> [Int] -> Int
no1 n c v s t y m = fromMaybe (-1) $ no1' n c v s t y m

no1' :: Int -> Int -> Int -> [Int] -> [Int] -> [Int] -> [Int] -> Maybe Int
no1' n c _ s t y m = maybeMinimum
    $ map time
    $ filter (\a -> place a == n)
    $ foldr ((\a b -> a b) . applyRoute)
        [PlaceCost { place = 1, coin = c, time = 0 }]
        $ createRouteList s t y m

-- [([PlaceCost] -> [PlaceCost])]

data PlaceCost = PlaceCost
    { place :: Int
    , coin :: Int
    , time :: Int
    } deriving (Show)

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

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

maybeMinimum :: (Ord a) => [a] -> Maybe a
maybeMinimum [] = Nothing
maybeMinimum x  = Just $ minimum x


applyRoute :: Route -> [PlaceCost] -> [PlaceCost]
applyRoute _ [] = []
applyRoute r (x:xs)
    | from r > place x = applyRoute r xs
    | from r < place x = x : applyRoute r xs
    | remainCoin < 0 = x : applyRoute r xs
    | otherwise = PlaceCost { place = to r, coin = remainCoin
            , time = tookTime } : x : applyRoute r xs
    where
      remainCoin = coin x - cost r
      tookTime = time x + rtime r
0