結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー e_gracilise_gracilis
提出日時 2015-06-17 16:26:14
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 996 bytes
コンパイル時間 5,225 ms
コンパイル使用メモリ 151,424 KB
最終ジャッジ日時 2023-11-11 15:07:31
合計ジャッジ時間 7,067 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:12:41: error:
    Ambiguous occurrence ‘B.getLine’
    It could refer to
       either ‘B.getLine’,
              imported qualified from ‘Data.ByteString.Char8’ at Main.hs:4:1-43
           or ‘B.getLine’,
              imported qualified from ‘Data.ByteString’ at Main.hs:3:1-37
   |
12 | getInt = fst . fromJust . B.readInt <$> B.getLine
   |                                         ^^^^^^^^^

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

ソースコード

diff #

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 $ sortBy (flip compare) as

solve :: [Int] -> Int
solve xs = (2^) $ length $ filter (/=0) $ sweep xs (1 `shiftL` 60)

sweep :: [Int] -> Int -> [Int]
sweep as 0 = as
sweep [] _ = []
sweep as@(x:_) b
  | x .&. b == 0 = sweep as (b `shiftR` 1)
  | otherwise = case sweep' as b of
    [] -> []
    p:ps -> p:sweep ps (b `shiftR` 1)

sweep' :: [Int] -> Int -> [Int]
sweep' [] _     = []
sweep' xs@(a:as) b
  | (a .&. b) == 0 = xs
  | otherwise      = a:(sortBy (flip compare) $ map f as)
  where
    f e = if e .&. b /= 0
            then e `xor` a
            else e
0