結果

問題 No.106 素数が嫌い!2
ユーザー かりあげクンかりあげクン
提出日時 2020-09-25 10:06:40
言語 Haskell
(9.8.2)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 875 bytes
コンパイル時間 18,430 ms
コンパイル使用メモリ 199,380 KB
実行使用メモリ 22,376 KB
最終ジャッジ日時 2023-09-10 14:28:10
合計ジャッジ時間 12,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
14,176 KB
testcase_01 AC 3 ms
7,056 KB
testcase_02 AC 3 ms
6,924 KB
testcase_03 AC 2 ms
7,056 KB
testcase_04 AC 22 ms
14,184 KB
testcase_05 AC 42 ms
22,288 KB
testcase_06 AC 32 ms
22,324 KB
testcase_07 AC 42 ms
22,376 KB
testcase_08 AC 4 ms
9,016 KB
testcase_09 AC 5 ms
9,084 KB
testcase_10 AC 42 ms
22,356 KB
testcase_11 AC 22 ms
12,992 KB
testcase_12 AC 42 ms
21,304 KB
testcase_13 AC 3 ms
6,928 KB
testcase_14 AC 3 ms
7,096 KB
testcase_15 AC 3 ms
7,020 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 #

import           Control.Arrow
import           Control.Monad
import qualified Data.ByteString.Char8       as BSC8
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

main :: IO ()
main = do
  (n, k) <- parse2
  solver n k >>= print . VU.length . VU.filter (>=k)

solver :: Int -> Int -> IO (VU.Vector Int)
solver n k = do
  table <- VU.unsafeThaw $ VU.replicate (n + 1) (0 :: Int)
  forM_ [2..n] $ \i -> do
    x <- VUM.read table i
    when (x == 0) $ do
      VUM.write table i 1
      forM_ [2 * i, 3 * i .. n] $ \j -> VUM.unsafeModify table (+1) j
  VU.unsafeFreeze table

type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)
parseInt :: Parser Int
parseInt = fmap (second BSC8.tail) . BSC8.readInt
parse2 :: IO (Int, Int)
parse2 = (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 parseInt <$> BSC8.getLine
0