結果

問題 No.153 石の山
ユーザー gigurururu
提出日時 2015-02-19 23:48:13
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 173,568 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 14:30:35
合計ジャッジ時間 2,337 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Bits
import Data.Array

mex :: [Int] -> Int
mex list = mex_sub 0 $ sort list
  where
    mex_sub n []      = n
    mex_sub n (x:xs)
      | n == x        = mex_sub (n+1) xs
      | otherwise     = n

grundy :: Int -> Int
grundy 0 = 0
grundy 1 = 0
grundy n = mex $ [foldl1 xor [dp !! (i`div`2) | i<-[n,n+1]]] ++ (if n<3 then [] else [foldl1 xor [dp !! (i`div`3) | i<-[n..n+2]]])

dp :: [Int]
dp = [grundy i | i <- [0..]]

main = do
  l <- (read::String->Int) <$> getLine
  putStrLn $ if dp!!l /= 0 then "A" else "B"
0