結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
|
提出日時 | 2021-03-19 23:57:22 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 220 ms / 1,000 ms |
コード長 | 650 bytes |
コンパイル時間 | 596 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-11-19 02:55:47 |
合計ジャッジ時間 | 4,381 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
Main.rb:7: warning: assigned but unused variable - number Main.rb:4: warning: assigned but unused variable - max Syntax OK
ソースコード
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]