結果

問題 No.1 道のショートカット
ユーザー karrym_karrym_
提出日時 2015-06-04 21:39:20
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 160,284 KB
実行使用メモリ 818,100 KB
最終ジャッジ日時 2023-09-22 12:17:59
合計ジャッジ時間 8,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,180 KB
testcase_01 AC 3 ms
6,996 KB
testcase_02 AC 2 ms
7,044 KB
testcase_03 AC 3 ms
7,072 KB
testcase_04 AC 2 ms
6,888 KB
testcase_05 AC 2 ms
7,100 KB
testcase_06 AC 3 ms
7,268 KB
testcase_07 AC 3 ms
7,368 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/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.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
0