結果

問題 No.130 XOR Minimax
ユーザー simansiman
提出日時 2020-10-21 13:12:33
言語 Ruby
(3.2.2)
結果
AC  
実行時間 1,376 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 11,304 KB
実行使用メモリ 56,048 KB
最終ジャッジ日時 2023-10-10 00:30:15
合計ジャッジ時間 15,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 668 ms
23,116 KB
testcase_01 AC 73 ms
15,356 KB
testcase_02 AC 71 ms
15,176 KB
testcase_03 AC 73 ms
15,176 KB
testcase_04 AC 122 ms
22,200 KB
testcase_05 AC 607 ms
56,048 KB
testcase_06 AC 475 ms
31,844 KB
testcase_07 AC 711 ms
49,100 KB
testcase_08 AC 1,376 ms
33,244 KB
testcase_09 AC 152 ms
17,028 KB
testcase_10 AC 188 ms
18,240 KB
testcase_11 AC 431 ms
29,932 KB
testcase_12 AC 109 ms
16,016 KB
testcase_13 AC 360 ms
23,784 KB
testcase_14 AC 1,223 ms
28,040 KB
testcase_15 AC 88 ms
15,648 KB
testcase_16 AC 882 ms
25,136 KB
testcase_17 AC 885 ms
25,488 KB
testcase_18 AC 963 ms
26,572 KB
testcase_19 AC 1,260 ms
27,220 KB
testcase_20 AC 620 ms
22,284 KB
testcase_21 AC 1,216 ms
28,304 KB
testcase_22 AC 336 ms
17,204 KB
testcase_23 AC 155 ms
15,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

def dfs(nums, mb)
  return nums.max if mb < 0

  base = 1 << mb
  cand = nums.group_by { |x| x[mb] }
  cand.default = []

  v = 0

  if cand[0].size > 0 && cand[1].size > 0
    v = [
      dfs(cand[0].map { |x| x ^ base }, mb - 1),
      dfs(cand[1], mb - 1)
    ].min
  elsif cand[0].size > 0
    v = dfs(cand[0], mb - 1)
  elsif cand[1].size > 0
    v = dfs(cand[1].map { |x| x ^ base }, mb - 1)
  end

  v
end

mb = A.map(&:bit_length).max
puts dfs(A, mb - 1)
0