結果

問題 No.698 ペアでチームを作ろう
ユーザー masashi0217masashi0217
提出日時 2021-03-19 23:57:22
言語 Ruby
(3.3.0)
結果
AC  
実行時間 203 ms / 1,000 ms
コード長 650 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-08-12 05:24:21
合計ジャッジ時間 4,618 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,324 KB
testcase_01 AC 79 ms
15,088 KB
testcase_02 AC 84 ms
15,016 KB
testcase_03 AC 74 ms
15,184 KB
testcase_04 AC 94 ms
15,220 KB
testcase_05 AC 187 ms
15,232 KB
testcase_06 AC 190 ms
15,188 KB
testcase_07 AC 189 ms
15,144 KB
testcase_08 AC 187 ms
15,300 KB
testcase_09 AC 190 ms
15,224 KB
testcase_10 AC 188 ms
15,300 KB
testcase_11 AC 192 ms
15,116 KB
testcase_12 AC 187 ms
15,288 KB
testcase_13 AC 189 ms
15,148 KB
testcase_14 AC 203 ms
15,276 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:7: warning: assigned but unused variable - number
Main.rb:4: warning: assigned but unused variable - max
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
bit = 1 << n
max = 0
dp = Array.new(1<<n,0)
0.upto(bit-1) do |i|
    number = 0
    team = 0
    0.upto(n) do |j|
        ij = i >> j
        if ij & 1 == 1
            team += 1
        end
    end
    next if team % 2 == 1
    #print "iは"+"#{i}" + " "+" teamは" + "#{team}" + "\n"
    0.upto(n-2) do |x|
        next if 1 << x & i != 0
        (x+1).upto(n-1) do |y|
            next if 1 << y & i != 0
            xx = 1 << x
            yy = 1 << y
            dp[i|xx|yy] = [dp[i|xx|yy],dp[i] + (a[x] ^ a[y])].max            
        end
    end
    #ここまではOK
end
puts dp[-1]
0