結果

問題 No.1 道のショートカット
ユーザー karrym_karrym_
提出日時 2015-06-04 22:43:29
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,107 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 163,812 KB
実行使用メモリ 22,156 KB
最終ジャッジ日時 2023-09-22 12:18:09
合計ジャッジ時間 9,348 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,040 KB
testcase_01 AC 2 ms
7,068 KB
testcase_02 AC 3 ms
7,052 KB
testcase_03 AC 3 ms
7,232 KB
testcase_04 AC 3 ms
7,108 KB
testcase_05 AC 3 ms
7,124 KB
testcase_06 AC 3 ms
7,068 KB
testcase_07 AC 3 ms
7,288 KB
testcase_08 AC 83 ms
12,100 KB
testcase_09 AC 82 ms
11,716 KB
testcase_10 AC 922 ms
12,196 KB
testcase_11 TLE -
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
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)
0