結果

問題 No.2 素因数ゲーム
ユーザー myuon
提出日時 2015-03-08 21:16:27
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 816 bytes
コンパイル時間 8,197 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 167,700 KB
最終ジャッジ日時 2024-06-24 16:42:32
合計ジャッジ時間 19,232 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 TLE * 1 -- * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:19:70: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
19 |   go x = printf "%010d" $ (read :: String -> Int) $ showIntAtBase 2 (head . show) x ""
   |                                                                      ^^^^

Main.hs:23:90: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
23 |     | otherwise = ((sum $ fmap (read . return . (!! 0)) ps) `mod` 2 == 0) && check (fmap tail ps)
   |                                                                                          ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Control.Monad
import Numeric
import Text.Printf

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]

primeVector n = go n sieve [0] where
  go 1 _ acc = reverse acc
  go k (p:ps) (a:acc)
    | k `mod` p == 0 = go (k `div` p) (p:ps) (a+1:acc)
    | otherwise = go k ps (0:a:acc)

solve n = if solve' n then "Bob" else "Alice"

solve' n = check $ fmap go $ primeVector n where
  go :: Int -> String
  go x = printf "%010d" $ (read :: String -> Int) $ showIntAtBase 2 (head . show) x ""
  
  check ps
    | all (== "") ps = True
    | otherwise = ((sum $ fmap (read . return . (!! 0)) ps) `mod` 2 == 0) && check (fmap tail ps)

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