結果

問題 No.7 プライムナンバーゲーム
ユーザー myuonmyuon
提出日時 2015-03-09 10:00:22
言語 Haskell
(9.8.2)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 613 bytes
コンパイル時間 4,277 ms
コンパイル使用メモリ 172,608 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:43:32
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 30 ms
6,948 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 10 ms
6,948 KB
testcase_07 AC 7 ms
6,948 KB
testcase_08 AC 4 ms
6,948 KB
testcase_09 AC 14 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 7 ms
6,948 KB
testcase_12 AC 22 ms
6,948 KB
testcase_13 AC 23 ms
6,948 KB
testcase_14 AC 30 ms
6,944 KB
testcase_15 AC 29 ms
6,944 KB
testcase_16 AC 27 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import Control.Applicative
import Data.List
import Data.Array

sieve' = 2:3:[6*i+j|i<-[1..],j<-[-1,1], isPrime $ 6*i+j] where
  isPrime n = null [p|p<-takeWhile (\x -> x*x <=n) sieve', rem n p == 0]

solve m ps = if solve' m ps then "Win" else "Lose"
solve' m ps = iter m ds where
  ds = [(2,False),(1,True),(0,True)]
  memo = listArray ((0,m)) $ fmap (\x -> iter x ds) $ [0..m]
  iter n acc = case lookup n acc of
    Just k -> k
    Nothing -> let h = not $ and [memo!(n-p)|p<-takeWhile (<n) ps, p<n] in h

main = do
    n <- (read :: String -> Int) <$> getLine
    putStrLn $ solve n $ takeWhile (<n) $ sieve'
0