結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2020-08-08 03:09:06 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,478 bytes |
コンパイル時間 | 5,531 ms |
コンパイル使用メモリ | 181,204 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-09-25 05:56:24 |
合計ジャッジ時間 | 7,303 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 WA * 8 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
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]]