結果
問題 | No.1072 A Nice XOR Pair |
ユーザー |
|
提出日時 | 2021-11-05 16:41:21 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,190 ms / 2,000 ms |
コード長 | 508 bytes |
コンパイル時間 | 101 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 32,512 KB |
最終ジャッジ日時 | 2024-11-06 07:19:56 |
合計ジャッジ時間 | 4,952 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 |
コンパイルメッセージ
Syntax OK
ソースコード
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