結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー e_gracilise_gracilis
提出日時 2015-06-18 15:28:14
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 882 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 158,336 KB
最終ジャッジ日時 2024-04-27 04:55:44
合計ジャッジ時間 1,028 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
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:13:41: error: [GHC-87543]
    Ambiguous occurrence ‘B.getLine’.
    It could refer to
       either ‘B.getLine’,
              imported qualified from ‘Data.ByteString.Char8’ at Main.hs:5:1-43,
           or ‘B.getLine’,
              imported qualified from ‘Data.ByteString’ at Main.hs:4:1-37.
   |
13 | getInt = fst . fromJust . B.readInt <$> B.getLine
   |                                         ^^^^^^^^^

Main.hs:15:60: error: [GHC-87543]
    Ambiguous occurrence ‘B.getLine’.
    It could refer to
       either ‘B.getLine’,
              imported qualified from ‘Data.ByteString.Char8’ at Main.hs:5:1-43,
           or ‘B.getLine’,
              imported qualified from ‘Data.ByteString’ at Main.hs:4:1-37.
   |
15 | getInts = map (fst . fromJust . B.readInt) <$> B.words <$> B.getLine
   |                                                            ^^^^^^^^^

ソースコード

diff #

module Main (main) where
import Data.Bits

import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B
import Control.Applicative
import Data.Maybe(fromJust)
import Data.List
import Debug.Trace
default (Int)

getInt :: IO Int
getInt = fst . fromJust . B.readInt <$> B.getLine
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) <$> B.words <$> B.getLine

main :: IO ()
main = do
  _n <- getInt
  as <- getInts
  print $ solve as

solve :: [Int] -> Int
solve = (2^) . length . traceShowId . sweep 60



sweep :: Int -> [Int] -> [Int]
sweep (-1) xs = xs
sweep b xs = case find (`testBit` b) xs of
  Nothing -> sweep (b-1) xs
  Just x  -> let
    xs' = map (f x) xs
    xs'' = filter (/= 0) xs'
    in
      x: sweep (b-1) xs''
  where
    f :: Int -> Int -> Int
    f x y = if 0 == (y .&. (1 `shiftL` b))
            then y
            else y `xor` x
0