結果

問題 No.1072 A Nice XOR Pair
ユーザー 小野寺健小野寺健
提出日時 2021-11-05 16:41:21
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,106 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 32,512 KB
最終ジャッジ日時 2024-04-24 00:45:35
合計ジャッジ時間 4,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
12,288 KB
testcase_01 AC 82 ms
12,032 KB
testcase_02 AC 82 ms
12,288 KB
testcase_03 AC 86 ms
12,288 KB
testcase_04 AC 83 ms
12,288 KB
testcase_05 AC 81 ms
12,288 KB
testcase_06 AC 88 ms
12,160 KB
testcase_07 AC 792 ms
29,312 KB
testcase_08 AC 213 ms
17,408 KB
testcase_09 AC 206 ms
17,408 KB
testcase_10 AC 220 ms
17,536 KB
testcase_11 AC 559 ms
22,400 KB
testcase_12 AC 1,106 ms
32,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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] = true
	zmax = a.bsearch_index{|i| i > z}
	zmax = N if not zmax
	zcnt = zmax - zmin
	cnt += ycnt * zcnt
}

puts cnt
0