結果
| 問題 |
No.658 テトラナッチ数列 Hard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-24 20:28:46 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 2,060 bytes |
| コンパイル時間 | 7,208 ms |
| コンパイル使用メモリ | 215,156 KB |
| 実行使用メモリ | 9,088 KB |
| 最終ジャッジ日時 | 2024-07-21 15:36:51 |
| 合計ジャッジ時間 | 8,133 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 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
ソースコード
{-# LANGUAGE BangPatterns #-}
import Control.Monad.State
import Data.Char
import Data.Coerce
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
main :: IO ()
main = do
t <- VUM.unsafeNew 10001
VUM.unsafeWrite t 0 (0 :: Int)
VUM.unsafeWrite t 1 (0 :: Int)
VUM.unsafeWrite t 2 (0 :: Int)
VUM.unsafeWrite t 3 (1 :: Int)
rep1 $ \i -> do
item1 <- VUM.unsafeRead t (i - 1)
item2 <- VUM.unsafeRead t (i - 2)
item3 <- VUM.unsafeRead t (i - 3)
item4 <- VUM.unsafeRead t (i - 4)
VUM.unsafeWrite t i ((item1 + item2 + item3 + item4) `mod` 17)
q <- readLn :: IO Int
qs <- parseN1 q
rep2 q $ \i -> print =<< VUM.unsafeRead t (mod (qs VU.! i) 4912)
stream1 :: Monad m => Int -> Int -> VFSM.Stream m Int
stream1 !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] stream1 #-}
rep1 :: Monad m => (Int -> m ()) -> m ()
rep1 = flip VFSM.mapM_ (stream1 4 10000)
{-# INLINE rep1 #-}
stream2 :: Monad m => Int -> Int -> VFSM.Stream m Int
stream2 !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] stream2 #-}
rep2 :: Monad m => Int -> (Int -> m ()) -> m ()
rep2 n = flip VFSM.mapM_ (stream2 0 n)
{-# INLINE rep2 #-}
type CParser a = StateT BSC8.ByteString Maybe a
runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString)
runCParser = runStateT
{-# INLINE runCParser #-}
int :: CParser Int
int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace
{-# INLINE int #-}
int1 :: CParser Int
int1 = fmap (subtract 1) int
{-# INLINE int1 #-}
parseN1 :: Int -> IO (VU.Vector Int)
parseN1 n = VU.unfoldrN n (runCParser int1) <$> BSC8.getContents
{-# INLINE parseN1 #-}