結果

問題 No.1072 A Nice XOR Pair
ユーザー yuruhiyayuruhiya
提出日時 2020-06-05 22:00:15
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 293 bytes
コンパイル時間 16,837 ms
コンパイル使用メモリ 257,008 KB
実行使用メモリ 17,328 KB
最終ジャッジ日時 2023-09-13 10:43:48
合計ジャッジ時間 18,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,460 KB
testcase_01 AC 2 ms
4,424 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,504 KB
testcase_06 AC 3 ms
4,516 KB
testcase_07 AC 47 ms
17,328 KB
testcase_08 AC 25 ms
4,932 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 37 ms
10,420 KB
testcase_12 AC 47 ms
17,292 KB
権限があれば一括ダウンロードができます

ソースコード

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 { |i| cnt[i] += 1 }

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