結果

問題 No.1 道のショートカット
ユーザー krotonkroton
提出日時 2015-06-05 20:20:11
言語 Haskell
(9.8.2)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 956 bytes
コンパイル時間 12,815 ms
コンパイル使用メモリ 163,948 KB
実行使用メモリ 13,040 KB
最終ジャッジ日時 2023-09-27 21:44:59
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,924 KB
testcase_01 AC 2 ms
7,028 KB
testcase_02 AC 2 ms
6,920 KB
testcase_03 AC 2 ms
7,088 KB
testcase_04 AC 2 ms
6,888 KB
testcase_05 AC 2 ms
6,888 KB
testcase_06 AC 2 ms
6,996 KB
testcase_07 AC 3 ms
7,044 KB
testcase_08 AC 42 ms
12,412 KB
testcase_09 AC 12 ms
11,944 KB
testcase_10 AC 32 ms
12,172 KB
testcase_11 AC 42 ms
12,356 KB
testcase_12 AC 132 ms
13,040 KB
testcase_13 AC 111 ms
12,868 KB
testcase_14 AC 4 ms
8,640 KB
testcase_15 AC 2 ms
6,916 KB
testcase_16 AC 6 ms
10,188 KB
testcase_17 AC 2 ms
6,920 KB
testcase_18 AC 4 ms
8,624 KB
testcase_19 AC 3 ms
8,300 KB
testcase_20 AC 22 ms
11,152 KB
testcase_21 AC 6 ms
9,084 KB
testcase_22 AC 4 ms
8,032 KB
testcase_23 AC 82 ms
12,404 KB
testcase_24 AC 102 ms
12,148 KB
testcase_25 AC 31 ms
11,332 KB
testcase_26 AC 22 ms
10,340 KB
testcase_27 AC 82 ms
12,220 KB
testcase_28 AC 2 ms
6,996 KB
testcase_29 AC 22 ms
12,516 KB
testcase_30 AC 6 ms
11,048 KB
testcase_31 AC 12 ms
11,544 KB
testcase_32 AC 32 ms
12,272 KB
testcase_33 AC 22 ms
11,908 KB
testcase_34 AC 72 ms
12,816 KB
testcase_35 AC 12 ms
11,368 KB
testcase_36 AC 22 ms
12,016 KB
testcase_37 AC 12 ms
11,844 KB
testcase_38 AC 3 ms
7,552 KB
testcase_39 AC 4 ms
8,844 KB
testcase_40 AC 6 ms
11,268 KB
testcase_41 AC 3 ms
8,192 KB
testcase_42 AC 2 ms
6,792 KB
testcase_43 AC 2 ms
6,896 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 Control.Applicative
import Data.List

main = do
    n <- read <$> getLine
    c <- read <$> getLine
    getLine
    s <- map read . words <$> getLine
    t <- map read . words <$> getLine
    y <- map read . words <$> getLine
    m <- map read . words <$> getLine
    print $ solve n c $ createRouteList s t y m

inf :: Int
inf = 2^20

solve :: Int -> Int -> [Route] -> Int
solve n cmax routes = if ans < inf then ans else -1
    where
        ans = f 1 cmax
        f m c | m == n = 0
              | otherwise = foldr min inf [(memo !! ((to r) - 1) !! (c - (cost r))) + (rtime r) | r <- es]
            where
                es = [r | r <- routes, (from r) == m, c - (cost r) >= 0]
        memo = [[f m c | c <- [0..cmax]] | m <- [1..n]]

data Route = Route
    { from :: Int
    , to :: Int
    , cost :: Int
    , rtime :: Int
    } deriving (Show)

createRouteList :: [Int] -> [Int] -> [Int] -> [Int] -> [Route]
createRouteList = zipWith4 Route
0