結果

問題 No.698 ペアでチームを作ろう
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-10 09:53:05
言語 Ruby
(3.3.0)
結果
AC  
実行時間 283 ms / 1,000 ms
コード長 406 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-08 12:49:01
合計ジャッジ時間 4,747 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
16,256 KB
testcase_01 AC 98 ms
16,256 KB
testcase_02 AC 106 ms
16,512 KB
testcase_03 AC 92 ms
16,256 KB
testcase_04 AC 132 ms
16,768 KB
testcase_05 AC 277 ms
17,152 KB
testcase_06 AC 283 ms
17,152 KB
testcase_07 AC 276 ms
17,152 KB
testcase_08 AC 275 ms
17,152 KB
testcase_09 AC 276 ms
17,152 KB
testcase_10 AC 275 ms
17,152 KB
testcase_11 AC 272 ms
17,152 KB
testcase_12 AC 277 ms
17,152 KB
testcase_13 AC 278 ms
17,152 KB
testcase_14 AC 277 ms
17,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

@n = gets.chomp.to_i
@a = gets.chomp.split.map(&:to_i)
@memo = {}

def solve(m)
  return @memo[m] if @memo[m]
  return 0 if m == 0

  max = 0
  (0...@n).to_a.each do |i|
    next if m & (1 << i) == 0

    ((i + 1)...@n).to_a.each do |j|
      next if m & (1 << j) == 0

      max = [max, solve(m & ~(1 << i) & ~(1 << j)) + (@a[i] ^ @a[j])].max
    end
  end

  @memo[m] = max
end

puts solve((1 << @n) - 1)
0