結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2015-03-08 20:37:35 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,062 bytes |
コンパイル時間 | 9,904 ms |
コンパイル使用メモリ | 189,568 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2024-07-08 03:49:58 |
合計ジャッジ時間 | 11,147 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 36 WA * 4 |
コンパイルメッセージ
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 Control.Applicative import Control.Monad import Data.Array import Data.Array.ST import Data.List import Data.Ord (comparing) solve n c arr = minimum $ fmap snd go where go = filter (\(k,v) -> fst k == n && v /= 1024) $ assocs arr' arr' = solve' n c arr solve' n c arr = last go where acc0 = (listArray ((1,0),(n,c)) $ repeat (2^31)) // [((1,c),0)] go = unfoldr f (1,acc0) f (i,acc) | i > n = Nothing | otherwise = Just (acc', (i+1,acc')) where current = filter (\(j,_) -> fst j == i) $ assocs acc acc' = accum min acc $ [((t,c-y),m+m0)|((i,c),m0) <- current, (t,y,m) <- arr!i, c-y >= 0] main = do n <- (read :: String -> Int) <$> getLine c <- (read :: String -> Int) <$> getLine _ <- getLine ss <- fmap (read :: String -> Int) . words <$> getLine ts <- fmap (read :: String -> Int) . words <$> getLine ys <- fmap (read :: String -> Int) . words <$> getLine ms <- fmap (read :: String -> Int) . words <$> getLine let arr = accumArray (flip (:)) [] (1,n) $ zip ss $ zip3 ts ys ms print $ solve n c arr