結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | 3405691582 |
提出日時 | 2017-03-21 11:44:11 |
言語 | Haskell (9.8.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 898 bytes |
コンパイル時間 | 1,300 ms |
コンパイル使用メモリ | 161,224 KB |
実行使用メモリ | 7,280 KB |
最終ジャッジ日時 | 2023-09-18 14:42:29 |
合計ジャッジ時間 | 7,553 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,124 KB |
testcase_01 | AC | 2 ms
7,280 KB |
testcase_02 | TLE | - |
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
ソースコード
import qualified Data.Map as M type Table = M.Map Int Bool main = do n <- read <$> getLine putStrLn $ if snd $ battle M.empty n then "Win" else "Lose" primesLeqN :: Int -> [Int] primesLeqN n = sieve [2..n] where sieve [] = [] sieve (n:ns) = n:sieve [m|m<-ns,mod m n/=0] {-battle :: Int -> Bool battle n | n <= 1 = True | otherwise = lookup not $ and $ battle <$> ((n-) <$> primesLeqN n)-} battle :: Table -> Int -> (Table,Bool) battle tbl n | n <= 1 = (tbl,True) | otherwise = case M.lookup n tbl of Just b -> (tbl,b) Nothing -> (M.insert n (not rslt) tbl',not rslt) where (tbl',rslt) = battleAux tbl n $ primesLeqN n battleAux tbl n [] = (tbl,True) battleAux tbl n (p:ps) = (tbl'',b && rslt') where (tbl''',b) = battle tbl (n-p) (tbl'',rslt') = battleAux tbl''' n ps