結果

問題 No.710 チーム戦
ユーザー letrangerjpletrangerjp
提出日時 2018-06-30 00:05:34
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 637 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 11,376 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2023-09-13 15:53:26
合計ジャッジ時間 5,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,344 KB
testcase_01 AC 79 ms
15,012 KB
testcase_02 AC 311 ms
15,268 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A, B = $<.map{|s| s.split.map &:to_i }.transpose

$ans = 1.0/0

def f(a, b, i, used)
  if i >= N
    # p [a,b]
    ab = [a, b].max
    $ans = ab if ab < $ans
    return
  end
  f(a, b, i+1, used)
  if [a-A[i], b+B[i]].max <= [a, b].max && used & (1 << i) == 0
    f(a-A[i], b+B[i], i+1, used)
  elsif [a+A[i], b-B[i]].max <= [a, b].max && used & (1 << i) != 0
    f(a+A[i], b-B[i], i+1, used)
  end
end

ais, bis = N.times.partition{|i|
  A[i] < B[i]
}

asum = ais.map{|i| A[i] }.sum
bsum = bis.map{|i| B[i] }.sum

# p [ais, asum]
# p [bis, bsum]

used = bis.inject(0){|r, i| r | (1 << i) }

f(asum, bsum, 0, used)

p $ans
0