結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー e_gracilise_gracilis
提出日時 2015-06-17 16:19:23
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 1,917 ms
コンパイル使用メモリ 161,052 KB
実行使用メモリ 24,884 KB
最終ジャッジ日時 2023-09-17 17:09:56
合計ジャッジ時間 8,699 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,212 KB
testcase_01 AC 2 ms
7,160 KB
testcase_02 AC 2 ms
7,208 KB
testcase_03 AC 2 ms
7,168 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
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,300 KB
testcase_19 AC 3 ms
7,060 KB
testcase_20 AC 32 ms
16,580 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
7,252 KB
testcase_24 RE -
testcase_25 AC 3 ms
7,188 KB
testcase_26 RE -
testcase_27 RE -
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 #

import Data.Bits

import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B
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 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:map f as
  where
    f e = if e .&. b /= 0
            then e `xor` a
            else e
0