結果

問題 No.211 素数サイコロと合成数サイコロ (1)
ユーザー こまるこまる
提出日時 2020-10-17 17:06:03
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 4,919 ms
コンパイル使用メモリ 186,908 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-28 08:23:30
合計ジャッジ時間 7,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,500 KB
testcase_01 AC 2 ms
7,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
7,560 KB
testcase_07 AC 2 ms
7,524 KB
testcase_08 WA -
testcase_09 AC 2 ms
7,508 KB
testcase_10 AC 2 ms
7,512 KB
testcase_11 WA -
testcase_12 AC 2 ms
7,468 KB
testcase_13 AC 2 ms
7,524 KB
testcase_14 AC 2 ms
7,516 KB
testcase_15 AC 2 ms
7,464 KB
testcase_16 AC 2 ms
7,524 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
7,580 KB
testcase_20 AC 3 ms
7,500 KB
testcase_21 AC 2 ms
7,584 KB
testcase_22 AC 2 ms
7,512 KB
testcase_23 AC 2 ms
7,580 KB
testcase_24 AC 2 ms
7,568 KB
testcase_25 AC 2 ms
7,680 KB
testcase_26 AC 2 ms
7,552 KB
testcase_27 AC 2 ms
7,628 KB
testcase_28 AC 2 ms
7,512 KB
testcase_29 AC 2 ms
7,564 KB
testcase_30 AC 2 ms
7,504 KB
testcase_31 AC 3 ms
7,552 KB
testcase_32 AC 2 ms
7,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/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