{-# LANGUAGE BangPatterns #-} import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do [h, a, d] <- map (read :: String -> Int) . words <$> getLine dp <- VUM.unsafeNew 10101 rep (h + 1) $ \i -> VUM.unsafeWrite dp i (0 :: Double) rep1 h $ \i -> do let preA = max (0 :: Int) (i - a) preD = max (0 :: Int) (i - d) item1 <- VUM.unsafeRead dp preA item2 <- VUM.unsafeRead dp preD VUM.unsafeWrite dp i (min (item1 + 1.0) (item2 + 1.5)) print =<< VUM.unsafeRead dp h stream :: Monad m => Int -> Int -> VFSM.Stream m Int stream !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 0 n) {-# INLINE rep #-} rep1 :: Monad m => Int -> (Int -> m ()) -> m () rep1 n = flip VFSM.mapM_ (stream 1 (n + 1)) {-# INLINE rep1 #-}