結果

問題 No.1072 A Nice XOR Pair
ユーザー yuruhiyayuruhiya
提出日時 2020-06-05 21:47:19
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 283 bytes
コンパイル時間 18,367 ms
コンパイル使用メモリ 256,772 KB
実行使用メモリ 17,416 KB
最終ジャッジ日時 2023-09-13 10:42:17
合計ジャッジ時間 20,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,416 KB
testcase_01 AC 3 ms
4,504 KB
testcase_02 AC 2 ms
4,396 KB
testcase_03 AC 2 ms
4,472 KB
testcase_04 AC 3 ms
4,480 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 24 ms
4,844 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, x = read_line.split.map &.to_i
a = n.times.map { read_line.to_i }
cnt = Hash(Int32, Int64).new(0)
a.each do |i|
  cnt[i] += 1
end

ans = 0_i64
cnt.each do |val, c|
  val2 = val ^ x
  if val != val2
    ans = c * cnt.fetch(val2, 0)
  else
    ans = c*(c - 1)//2
  end
end
puts ans
0