結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-07 17:42:58 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 160 ms / 5,000 ms |
| コード長 | 683 bytes |
| コンパイル時間 | 5,789 ms |
| コンパイル使用メモリ | 201,172 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-10-01 16:11:46 |
| 合計ジャッジ時間 | 7,518 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
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
ソースコード
import Control.Applicative ((<$>))
import Data.Bool (bool)
import Data.List (unfoldr, foldl')
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
main :: IO ()
main = solve <$> readLn >>= putStrLn
solve :: Int -> String
solve n = bool "Lose" "Win" (dp ! n)
where dp = foldl' f (V.replicate (n+1) True) [2 .. n]
where f v x = let b = bool True False . and . map ((dp !) . (x -)) . takeWhile (<= x) $ primes
in v // [(x, b)]
primes :: [Int]
primes = 2 : 3 : 5 : 7 : unfoldr f 11
where f x | isP x = Just (x, x+2)
| otherwise = f (x+2)
isP x = all ((/=0) . (mod x)) . takeWhile ((<= x) . (^ 2)) $ primes