結果
| 問題 |
No.1 道のショートカット
|
| ユーザー |
|
| 提出日時 | 2015-03-08 20:39:25 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 1,104 bytes |
| コンパイル時間 | 10,124 ms |
| コンパイル使用メモリ | 189,952 KB |
| 実行使用メモリ | 13,696 KB |
| 最終ジャッジ日時 | 2024-07-20 16:11:34 |
| 合計ジャッジ時間 | 11,671 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
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)
big = 2^31
solve n c arr = let r = fmap snd go in if r == [] then -1 else minimum r where
go = filter (\(k,v) -> fst k == n && v /= big) $ assocs arr'
arr' = solve' n c arr
solve' n c arr = last go where
acc0 = (listArray ((1,0),(n,c)) $ repeat big) // [((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