結果

問題 No.91 赤、緑、青の石
ユーザー siman
提出日時 2015-04-02 20:09:53
言語 Ruby
(3.4.1)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-24 06:47:25
合計ジャッジ時間 4,351 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Yukicoder
  attr_reader :red, :green, :blue

  def initialize
    @red, @green, @blue = gets.chomp.split(' ').map(&:to_i)

    min_count = 0
    max_count = 10000000
    create_count = 0

    while min_count < max_count
      create_count = (min_count + max_count) / 2

      if can_create?(create_count)
        min_count = create_count + 1
      else
        max_count = create_count
      end
    end

    puts min_count - 1
  end

  def can_create?(count)
    rest_count = 0
    rest_count += [0, red - count].max / 2
    rest_count += [0, green - count].max / 2
    rest_count += [0, blue - count].max / 2

    rest_count -= [0, count - red].max
    rest_count -= [0, count - green].max
    rest_count -= [0, count - blue].max

    rest_count >= 0
  end
end

Yukicoder.new
0