結果

問題 No.1 道のショートカット
ユーザー 情報学生情報学生
提出日時 2020-08-08 03:09:06
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,478 bytes
コンパイル時間 4,296 ms
コンパイル使用メモリ 188,108 KB
実行使用メモリ 8,836 KB
最終ジャッジ日時 2023-10-25 21:09:10
合計ジャッジ時間 7,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,464 KB
testcase_01 AC 2 ms
5,464 KB
testcase_02 AC 2 ms
5,464 KB
testcase_03 AC 2 ms
5,472 KB
testcase_04 AC 3 ms
5,440 KB
testcase_05 AC 3 ms
5,464 KB
testcase_06 AC 2 ms
5,472 KB
testcase_07 AC 2 ms
5,492 KB
testcase_08 AC 31 ms
8,292 KB
testcase_09 AC 12 ms
7,272 KB
testcase_10 AC 21 ms
7,228 KB
testcase_11 AC 32 ms
7,484 KB
testcase_12 AC 62 ms
8,828 KB
testcase_13 AC 51 ms
8,836 KB
testcase_14 AC 3 ms
5,948 KB
testcase_15 AC 3 ms
5,436 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,468 KB
testcase_18 AC 2 ms
5,900 KB
testcase_19 AC 3 ms
6,024 KB
testcase_20 AC 4 ms
6,300 KB
testcase_21 AC 4 ms
6,124 KB
testcase_22 AC 2 ms
5,804 KB
testcase_23 AC 32 ms
7,612 KB
testcase_24 AC 32 ms
7,368 KB
testcase_25 AC 6 ms
6,320 KB
testcase_26 AC 4 ms
6,156 KB
testcase_27 AC 32 ms
7,680 KB
testcase_28 AC 2 ms
5,532 KB
testcase_29 AC 21 ms
7,488 KB
testcase_30 AC 3 ms
5,964 KB
testcase_31 AC 7 ms
6,504 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 4 ms
6,820 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
5,600 KB
testcase_39 WA -
testcase_40 AC 3 ms
6,048 KB
testcase_41 WA -
testcase_42 AC 2 ms
5,444 KB
testcase_43 AC 2 ms
5,436 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/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 :: ((c, b1), b2) -> c
from = fst . fst
to :: ((a, c), b) -> c
to = snd . fst
cost :: (a, (c, b)) -> c
cost = fst . snd
time :: (a1, (a2, c)) -> c
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' _n _c
            | _n == n = 0
            | otherwise = List.foldr min inf [(table List.!! ((to r) - 1) List.!! (c - (cost r))) + (time r) | r <- es]
            where
                es = [r | r <- xs, (from r) == _n, _c - (cost r) >= 0]
        table = [[solver' _n _c | _c <- [0..c]] | _n <- [1..n]]
0