結果

問題 No.1072 A Nice XOR Pair
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 16:39:53
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 503 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 29,184 KB
最終ジャッジ日時 2024-04-24 00:44:05
合計ジャッジ時間 4,520 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
17,536 KB
testcase_01 AC 92 ms
12,288 KB
testcase_02 AC 83 ms
12,160 KB
testcase_03 AC 82 ms
12,288 KB
testcase_04 AC 87 ms
12,288 KB
testcase_05 AC 81 ms
12,288 KB
testcase_06 AC 99 ms
12,288 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, X = gets.split(" ").map{|s| s.to_i}
a = []

N.times {
	a << gets.to_i
}

a.sort!

used = []

cnt = 0
a.uniq.each {|y|
	next if used.include?(y)
	ymin = a.bsearch_index{|i| i >= y}
	ymax = a.bsearch_index{|i| i > y}
	ymax = N if not ymax
	ycnt = ymax - ymin
	z = y ^ X
	if z == y then
		cnt += ycnt * (ycnt - 1) / 2
		next
	end
	zmin = a.bsearch_index{|i| i >= z}
	next if not zmin
	used << z
	zmax = a.bsearch_index{|i| i > z}
	zmax = N if not zmax
	zcnt = zmax - zmin
	cnt += ycnt * zcnt
}

puts cnt
0