結果

問題 No.144 エラトステネスのざる
ユーザー okadukiokaduki
提出日時 2015-02-06 01:10:28
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 678 bytes
コンパイル時間 3,693 ms
コンパイル使用メモリ 165,092 KB
実行使用メモリ 26,556 KB
最終ジャッジ日時 2023-09-05 14:12:03
合計ジャッジ時間 7,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
26,556 KB
testcase_01 AC 3 ms
7,420 KB
testcase_02 AC 3 ms
7,652 KB
testcase_03 AC 2 ms
7,452 KB
testcase_04 AC 3 ms
7,432 KB
testcase_05 AC 3 ms
7,420 KB
testcase_06 AC 33 ms
15,104 KB
testcase_07 AC 33 ms
15,164 KB
testcase_08 AC 32 ms
15,120 KB
testcase_09 AC 32 ms
15,064 KB
testcase_10 AC 32 ms
15,120 KB
testcase_11 AC 32 ms
15,136 KB
testcase_12 AC 32 ms
15,108 KB
testcase_13 TLE -
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 Text.Printf

main = do
  [sn, sp] <- words <$> getLine
  let 
    n = (read :: String -> Int) sn
    p = (read :: String -> Double) sp
    in
   print $ solve n p
    
solve :: Int -> Double -> Double   
solve n p = solve_ 2 [1.0,1.0 ..]
  where
    solve_ :: Int -> [Double] -> Double
    solve_ i (x:xs)
      | i == n = x
      | otherwise = (+x) $ solve_ (i+1) $ app (\y->y*(1.0 - p)) (i+1) i xs
    app :: (Double -> Double) -> Int -> Int -> [Double] -> [Double]
    app f i m ys@(x:xs) 
      | i > n = ys
      | otherwise = if i `mod` m == 0
                    then (f x) : app f (i+1) m xs
                    else x: app f (i+1) m xs
0