結果

問題 No.1072 A Nice XOR Pair
ユーザー simansiman
提出日時 2020-10-07 18:42:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 341 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 47,168 KB
最終ジャッジ日時 2023-09-27 09:21:33
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,104 KB
testcase_01 AC 79 ms
15,248 KB
testcase_02 AC 79 ms
15,296 KB
testcase_03 AC 79 ms
15,260 KB
testcase_04 AC 79 ms
15,000 KB
testcase_05 AC 79 ms
15,268 KB
testcase_06 AC 83 ms
15,508 KB
testcase_07 AC 368 ms
38,256 KB
testcase_08 AC 213 ms
19,036 KB
testcase_09 AC 210 ms
18,988 KB
testcase_10 AC 213 ms
18,956 KB
testcase_11 AC 275 ms
26,920 KB
testcase_12 AC 411 ms
47,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, X = gets.split.map(&:to_i)
A = N.times.map { gets.to_i }
checked = Hash.new(false)

C = A.tally
C.default = 0
ans = 0

A.uniq.each do |a|
  next if checked[a]
  checked[a] = true

  y = X ^ a
  checked[y] = true
  cnt = C[y]

  next if cnt == 0

  if a == y
    ans += cnt * (cnt - 1) / 2
  else
    ans += cnt * C[a]
  end
end

puts ans
0