結果

問題 No.1 道のショートカット
ユーザー 情報学生情報学生
提出日時 2020-08-08 03:32:53
言語 Haskell
(9.8.2)
結果
AC  
実行時間 182 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 4,294 ms
コンパイル使用メモリ 161,260 KB
実行使用メモリ 11,024 KB
最終ジャッジ日時 2023-09-27 22:31:48
合計ジャッジ時間 7,086 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,376 KB
testcase_01 AC 2 ms
7,384 KB
testcase_02 AC 2 ms
7,600 KB
testcase_03 AC 2 ms
7,460 KB
testcase_04 AC 2 ms
7,380 KB
testcase_05 AC 2 ms
7,444 KB
testcase_06 AC 2 ms
7,436 KB
testcase_07 AC 2 ms
7,396 KB
testcase_08 AC 42 ms
10,124 KB
testcase_09 AC 11 ms
9,124 KB
testcase_10 AC 31 ms
9,240 KB
testcase_11 AC 52 ms
9,616 KB
testcase_12 AC 182 ms
11,024 KB
testcase_13 AC 162 ms
10,900 KB
testcase_14 AC 3 ms
7,832 KB
testcase_15 AC 2 ms
7,400 KB
testcase_16 AC 4 ms
8,096 KB
testcase_17 AC 3 ms
7,372 KB
testcase_18 AC 2 ms
7,808 KB
testcase_19 AC 3 ms
7,928 KB
testcase_20 AC 11 ms
8,196 KB
testcase_21 AC 4 ms
8,020 KB
testcase_22 AC 3 ms
7,860 KB
testcase_23 AC 112 ms
9,728 KB
testcase_24 AC 132 ms
9,476 KB
testcase_25 AC 32 ms
8,324 KB
testcase_26 AC 22 ms
8,144 KB
testcase_27 AC 122 ms
9,792 KB
testcase_28 AC 2 ms
7,448 KB
testcase_29 AC 21 ms
9,564 KB
testcase_30 AC 4 ms
7,916 KB
testcase_31 AC 7 ms
8,564 KB
testcase_32 AC 41 ms
9,492 KB
testcase_33 AC 22 ms
8,836 KB
testcase_34 AC 82 ms
9,732 KB
testcase_35 AC 3 ms
8,896 KB
testcase_36 AC 11 ms
8,856 KB
testcase_37 AC 4 ms
8,628 KB
testcase_38 AC 2 ms
7,556 KB
testcase_39 AC 3 ms
7,972 KB
testcase_40 AC 4 ms
7,980 KB
testcase_41 AC 3 ms
7,588 KB
testcase_42 AC 2 ms
7,360 KB
testcase_43 AC 2 ms
7,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 qualified Control.Monad         as Monad
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Char             as Char
import qualified Data.List             as List

getInt :: IO [Int]
getInt = List.unfoldr f <$> BSC8.getLine
    where
        f s = do
            (n, s') <- BSC8.readInt s
            return (n, BSC8.dropWhile Char.isSpace s')

getMultiLineInt :: Int -> IO [[Int]]
getMultiLineInt n = Monad.replicateM n getInt

main :: IO ()
main = do
    n <- readLn :: IO Int
    c <- readLn :: IO Int
    _ <- readLn :: IO Int
    xs <- map _func . List.transpose <$> getMultiLineInt 4
    print $ solver n c xs

type City  = Int
type Time  = Int
type Money = Int

inf :: Int
inf = 1000000007

_func :: [Int] -> ((City, City), (Money, Time))
_func (a:b:c:d:_) = ((a, b), (c, d))
_func _           = error "error"


from :: ((City, City), (Money, Time)) -> City
from = fst . fst
to :: ((City, City), (Money, Time))   -> City
to = snd . fst
cost :: ((City, City), (Money, Time)) -> Money
cost = fst . snd
time :: ((City, City), (Money, Time)) -> Time
time = snd . snd

solver :: Int -> Int -> [((City, City), (Money, Time))] -> Int
solver n c xs = if ans < inf then ans else -1
    where
        ans = solver' 1 c
        solver' m c'
            | m == n = 0
            | otherwise = foldr min inf [(table !! ((to r) - 1) !! (c' - (cost r))) + (time r) | r <- es]
            where
                es = [r | r <- xs, (from r) == m, c' - (cost r) >= 0]
        table = [[solver' k d | d <- [0..c]] | k <- [1..n]]
0