結果

問題 No.91 赤、緑、青の石
ユーザー tshigtshig
提出日時 2016-08-05 12:34:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 619 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 11,612 KB
実行使用メモリ 15,308 KB
最終ジャッジ日時 2023-09-06 12:22:30
合計ジャッジ時間 3,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,128 KB
testcase_01 AC 78 ms
15,080 KB
testcase_02 AC 78 ms
15,308 KB
testcase_03 AC 78 ms
15,028 KB
testcase_04 AC 77 ms
15,248 KB
testcase_05 AC 78 ms
15,124 KB
testcase_06 AC 79 ms
15,164 KB
testcase_07 AC 79 ms
15,152 KB
testcase_08 AC 78 ms
15,128 KB
testcase_09 AC 78 ms
15,196 KB
testcase_10 AC 77 ms
15,052 KB
testcase_11 AC 77 ms
15,124 KB
testcase_12 AC 77 ms
15,048 KB
testcase_13 AC 77 ms
15,092 KB
testcase_14 AC 77 ms
15,260 KB
testcase_15 AC 78 ms
15,116 KB
testcase_16 AC 78 ms
15,092 KB
testcase_17 AC 78 ms
15,216 KB
testcase_18 AC 77 ms
15,152 KB
testcase_19 AC 77 ms
15,120 KB
testcase_20 AC 76 ms
15,148 KB
testcase_21 AC 78 ms
15,296 KB
testcase_22 AC 77 ms
15,120 KB
testcase_23 AC 77 ms
15,116 KB
testcase_24 AC 77 ms
15,136 KB
testcase_25 AC 77 ms
15,088 KB
testcase_26 AC 77 ms
15,256 KB
testcase_27 AC 77 ms
15,052 KB
testcase_28 AC 77 ms
15,288 KB
testcase_29 AC 78 ms
15,288 KB
testcase_30 AC 78 ms
15,264 KB
testcase_31 AC 78 ms
15,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Calc0091
  def initialize(args)
    args = args.map { |l| l.chomp.split(/\s+/) }
    @r, @g, @b = args.shift.map(&:to_i)
  end

  def run
    min, max = 0, (@r + @g + @b) / 3 + 1
    bs(min, max)
  end

  def bs(min, max)
    cur = (min + max) / 2
    if cur == min
      cur
    else
      check(cur) ? bs(cur, max) : bs(min, cur)
    end
  end

  def check(k)
    lack = [@r, @g, @b].map { |s| k - s }.select(&:positive?).inject(:+) || 0
    excess = [@r, @g, @b].map { |s| (s - k) / 2 }.select(&:positive?).inject(:+) || 0
    excess >= lack
  end
end

puts Calc0091.new(STDIN.readlines).run if __FILE__ == $0
0