結果

問題 No.1072 A Nice XOR Pair
ユーザー 小野寺健
提出日時 2021-11-05 17:25:10
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 91,568 KB
最終ジャッジ日時 2024-11-06 08:12:24
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 5 TLE * 1 -- * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
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