結果

問題 No.144 エラトステネスのざる
ユーザー gigurururugigurururu
提出日時 2015-02-08 21:47:58
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 589 bytes
コンパイル時間 9,422 ms
コンパイル使用メモリ 164,924 KB
実行使用メモリ 536,084 KB
最終ジャッジ日時 2023-09-05 11:13:04
合計ジャッジ時間 12,255 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,912 KB
testcase_01 AC 3 ms
7,476 KB
testcase_02 AC 2 ms
7,440 KB
testcase_03 AC 3 ms
7,480 KB
testcase_04 AC 3 ms
7,520 KB
testcase_05 AC 3 ms
7,508 KB
testcase_06 AC 3 ms
7,884 KB
testcase_07 AC 3 ms
8,228 KB
testcase_08 AC 4 ms
8,020 KB
testcase_09 AC 3 ms
7,904 KB
testcase_10 AC 3 ms
7,904 KB
testcase_11 AC 4 ms
8,084 KB
testcase_12 AC 3 ms
8,028 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Applicative
import Data.Array.IO
import Data.Array

readInt :: String -> Int
readInt = read

readDouble :: String -> Double
readDouble = read

sumA :: [Int] -> Array Int Double -> Double
sumA indexes ary = foldl (\ acc i -> acc + ary!i) 0.0 indexes

main :: IO()
main = do
  [ns,ps] <- words <$> getLine
  let n = readInt ns
  let m = n + 1
  let p = readDouble ps
  l <- newArray (2,m) 1.0 :: IO(IOArray Int Double)
  sequence_ [sequence_ [(writeArray l j) =<< (*) (1-p) <$> (readArray l j) | j <- [i+i,i+i+i..n]] | i <- [2,3..n] ]
  print =<< (sumA [2,3..n] <$> freeze l)
0