結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー e_gracilise_gracilis
提出日時 2015-06-18 14:06:31
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 932 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 160,904 KB
実行使用メモリ 25,996 KB
最終ジャッジ日時 2023-09-17 17:12:00
合計ジャッジ時間 7,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
7,324 KB
testcase_03 AC 2 ms
7,328 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
7,164 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
7,512 KB
testcase_19 AC 3 ms
7,192 KB
testcase_20 AC 43 ms
15,336 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
7,400 KB
testcase_24 AC 3 ms
7,316 KB
testcase_25 AC 3 ms
7,392 KB
testcase_26 AC 3 ms
7,304 KB
testcase_27 AC 3 ms
7,348 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

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

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

sweep :: Int -> [Int] -> [Int]
sweep 0 as = as
sweep _ [] = []
sweep b as = sweep (b `shiftR` 1) $ sweepBy as b

sweepBy :: [Int] -> Int -> [Int]
sweepBy [] _ = []
sweepBy xs b = case find ((0/=) . (b .&.)) xs of
  Nothing -> xs
  Just x  -> x:(filter (/=0) . map (f x)) xs
  where
    f x y = if y .&. b == 0
            then y
            else x `xor` y
0