結果

問題 No.1 道のショートカット
コンテスト
ユーザー karrym_
提出日時 2015-06-04 22:43:29
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,107 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,218 ms
コンパイル使用メモリ 193,280 KB
実行使用メモリ 31,136 KB
最終ジャッジ日時 2026-03-29 20:54:12
合計ジャッジ時間 8,254 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 TLE * 1 -- * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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