結果

問題 No.7 プライムナンバーゲーム
ユーザー aimyaimy
提出日時 2017-04-28 10:12:08
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 822 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 159,728 KB
実行使用メモリ 812,764 KB
最終ジャッジ日時 2023-10-11 17:21:49
合計ジャッジ時間 12,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Data.Tuple
import Data.List
import Data.Bool
import Data.Bits

data Tree a = Node a (Tree a) (Tree a)
memoize f = memof where memof = f (query (blank memof))
blank f = blank' 1 where blank' k = Node (f k) (blank' (2*k)) (blank' (2*k+1))

query m x = query' m bits
 where
  bits = reverse (take w (unfoldr (return . swap . flip divMod 2) x))
  w = floor (logBase 2 (fromIntegral x))
  query' (Node v left right) bs
   | bs == [] = v
   | head bs == 0 = query' left (tail bs)
   | otherwise = query' right (tail bs)

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i <- takeWhile (\x -> x^2 <= n) primes, mod n i == 0]

main = readLn >>= putStrLn . bool "Lose" "Win" . pgame

pgame = memoize $ \f n -> if n<=3 then False else all (not . f . (n-)) (takeWhile (<=n) primes)
0