結果

問題 No.211 素数サイコロと合成数サイコロ (1)
ユーザー こまる
提出日時 2020-10-17 17:06:03
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 8,943 ms
コンパイル使用メモリ 196,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 02:52:58
合計ジャッジ時間 10,147 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 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

ソースコード

diff #

{-# LANGUAGE BangPatterns    #-}

import           Control.Monad
import           Data.IORef
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
  k   <- readLn :: IO Int
  ret <- newIORef (0.0 :: Float)
  as <- VU.unsafeThaw . VU.fromList $ ([2, 3, 5, 7, 11, 13] :: [Int])
  bs <- VU.unsafeThaw . VU.fromList $ ([4, 6, 8, 9, 10, 12] :: [Int])
  rep 6 $ \i -> rep 6 $ \j -> do
    a <- VUM.unsafeRead as i
    b <- VUM.unsafeRead bs j
    when (a * b == k) $ modifyIORef ret (+ 1.0)
  modifyIORef ret (\u -> u / 36)
  print =<< readIORef ret

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)
0