結果

問題 No.1072 A Nice XOR Pair
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 17:25:10
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 91,820 KB
最終ジャッジ日時 2024-04-24 01:34:01
合計ジャッジ時間 4,626 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:12: warning: assigned but unused variable - i
Syntax OK

ソースコード

diff #

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

N.times {
	a << gets.to_i
}

a.sort!

cnt = 0

i = 0

while a and a.length > 0 do
	y = a[0]
	ycnt = a.bsearch_index{|i| i > y}
	ycnt = a.length if not ycnt
	z = y ^ X
	a = a[ycnt..-1]
	if z == y then
		cnt += ycnt * (ycnt - 1) / 2
		next
	end
	zmin = a.bsearch_index{|i| i >= z}
	next if not zmin
	zmax = a.bsearch_index{|i| i > z}
	zmax = a.length if not zmax
	zcnt = zmax - zmin
	cnt += ycnt * zcnt
	break if zmax == a.length
	a = a[0, zmin] + a[zmax..-1]
end
0