![見出し画像](https://assets.st-note.com/production/uploads/images/161636671/rectangle_large_type_2_015692aadb8b778fd24f5859a3b36928.png?width=1200)
IPO 見本
競プロ典型 90 問 42 日目 - Multiple of 9(★4)
import Control.Monad
import qualified Data.Vector.Unboxed.Mutable as UM
main = readLn >>= sol >>= print
sol k = case k `mod` 9 of
0 -> f9 k
_ -> return 0
p = 10^9+7
f9 k = do
u <- UM.replicate (k+9) 0
forM_ [0..7] $ \i -> UM.write u i (0 :: Int)
UM.write u 8 1
forM_ [9..k+8] $ \i ->
foldM (\s j -> (`mod` p) . (+ s) <$> UM.read u j) 0 [i-9..i-1]
>>= UM.write u i
UM.read u (k+8)
いいなと思ったら応援しよう!
![karoyakani](https://assets.st-note.com/production/uploads/images/153060341/profile_9698d87ebc4a2db16c1de3967836ae3d.jpg?width=600&crop=1:1,smart)