結果

問題 No.1072 A Nice XOR Pair
ユーザー 👑 obakyanobakyan
提出日時 2020-06-05 23:40:33
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 510 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 13,692 KB
最終ジャッジ日時 2023-08-22 18:21:45
合計ジャッジ時間 1,493 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 77 ms
13,564 KB
testcase_08 AC 68 ms
4,376 KB
testcase_09 AC 46 ms
4,380 KB
testcase_10 AC 49 ms
4,376 KB
testcase_11 AC 53 ms
6,124 KB
testcase_12 AC 77 ms
13,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local xor = bit.bxor
local n, x = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local tmap = {}
for i = 1, n do
  local v = t[i]
  if not tmap[v] then
    tmap[v] = 1
  else
    tmap[v] = tmap[v] + 1
  end
end
local ret = 0
if x == 0 then
  for k, v in pairs(tmap) do
    ret = ret + math.floor(v * (v - 1) / 2)
  end
  print(ret)
else
  for i = 1, n do
    local dst = xor(x, t[i])
    if tmap[dst] then
      ret = ret + tmap[dst]
    end
  end
  print(math.floor(ret / 2))
end
0