結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー e_gracilise_gracilis
提出日時 2015-06-17 16:22:01
言語 Haskell
(9.8.2)
結果
RE  
実行時間 -
コード長 980 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 162,612 KB
実行使用メモリ 25,988 KB
最終ジャッジ日時 2023-09-17 17:11:48
合計ジャッジ時間 36,633 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,164 KB
testcase_01 AC 2 ms
7,100 KB
testcase_02 AC 3 ms
7,180 KB
testcase_03 RE -
testcase_04 AC 2 ms
7,152 KB
testcase_05 AC 2 ms
7,192 KB
testcase_06 RE -
testcase_07 AC 3 ms
7,244 KB
testcase_08 AC 1,432 ms
22,716 KB
testcase_09 AC 203 ms
14,088 KB
testcase_10 AC 1,042 ms
18,664 KB
testcase_11 AC 673 ms
17,548 KB
testcase_12 AC 1,752 ms
22,748 KB
testcase_13 AC 1,923 ms
24,836 KB
testcase_14 AC 1,003 ms
18,588 KB
testcase_15 AC 2,073 ms
25,696 KB
testcase_16 AC 1,702 ms
22,720 KB
testcase_17 AC 1,862 ms
24,788 KB
testcase_18 AC 3 ms
7,364 KB
testcase_19 AC 2 ms
7,084 KB
testcase_20 AC 32 ms
18,456 KB
testcase_21 AC 2,161 ms
25,868 KB
testcase_22 AC 2,123 ms
25,988 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 1,173 ms
20,796 KB
testcase_29 AC 1,772 ms
24,836 KB
testcase_30 AC 1,443 ms
21,704 KB
testcase_31 AC 1,252 ms
20,700 KB
testcase_32 AC 1,572 ms
22,772 KB
testcase_33 AC 2,022 ms
25,704 KB
testcase_34 AC 2,022 ms
25,856 KB
testcase_35 AC 2,113 ms
25,904 KB
testcase_36 AC 2,032 ms
25,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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 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