結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2015-06-04 21:39:20 |
言語 | Haskell (9.10.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,088 bytes |
コンパイル時間 | 9,928 ms |
コンパイル使用メモリ | 175,308 KB |
実行使用メモリ | 813,696 KB |
最終ジャッジ日時 | 2024-07-08 04:03:56 |
合計ジャッジ時間 | 9,577 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 MLE * 1 -- * 35 |
コンパイルメッセージ
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 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 $ makeRoad n ss ts ys ms where search :: (Int, Int) -> Maybe Int -> Maybe Int search (y, m) Nothing = if y <= c then Just m else Nothing search (y, m) (Just t) = if y <= c && m < t then Just m else Just t makeRoad :: Int -> [Int] -> [Int] -> [Int] -> [Int] -> [(Int, Int)] makeRoad n ss ts ys ms = do to <- elemIndices n ts let from = ss !! to money = ys !! to time = ms !! to if from == 1 then return (money, time) else ((+ money) *** (+ time)) <$> makeRoad from ss ts ys ms