結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2015-06-04 22:43:29 |
言語 | Haskell (9.10.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,107 bytes |
コンパイル時間 | 9,579 ms |
コンパイル使用メモリ | 172,160 KB |
実行使用メモリ | 27,808 KB |
最終ジャッジ日時 | 2024-07-08 04:04:13 |
合計ジャッジ時間 | 10,475 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 TLE * 1 -- * 32 |
コンパイルメッセージ
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
ソースコード
import Data.Maybe import Data.List import Control.Arrow import Control.Applicative import Control.Monad main :: IO () main = do n <- read <$> getLine c <- read <$> getLine getLine ss <- map read . words <$> getLine ts <- map read . words <$> getLine ys <- map read . words <$> getLine ms <- map read . words <$> getLine print $ fromMaybe (-1) $ solve n c ss ts ys ms solve :: Int -> Int -> [Int] -> [Int] -> [Int] -> [Int] -> Maybe Int solve n c ss ts ys ms = foldr search Nothing road where road = makeRoad n c ss ts ys ms 0 search :: Int -> Maybe Int -> Maybe Int search m Nothing = Just m search m (Just t) = if m < t then Just m else Just t makeRoad :: Int -> Int -> [Int] -> [Int] -> [Int] -> [Int] -> Int -> [Int] makeRoad n c ss ts ys ms cost = do to <- elemIndices n ts let from = ss !! to money = ys !! to time = ms !! to when (cost + money > c) mzero if from == 1 then return time else map (+ time) $ makeRoad from c ss ts ys ms (cost + money)