結果

問題 No.9 モンスターのレベル上げ
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2015-01-26 02:23:00
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,209 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 20,000 KB
最終ジャッジ日時 2023-09-05 06:52:37
合計ジャッジ時間 7,318 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,084 KB
testcase_01 AC 80 ms
15,084 KB
testcase_02 TLE -
testcase_03 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Party
  attr_reader :size
  def initialize(level_list)
    @level_list = level_list.clone
    @size = @level_list.size
  end

  def clone
    return self.class.new(@level_list)
  end

  def level_each_with_start_pos(start_pos)
    @size.times do |i|
      pos = (start_pos + i) % @size
      yield @level_list[pos]
    end
  end
end

class OwnParty < Party
  def initialize(level_list)
    super
    @count_list = [0] * @level_list.size
  end

  def clone
    clone_op = super
    clone_op.set_count_list(@count_list)
    return clone_op
  end

  def set_count_list(count_list)
    @count_list = count_list.clone
  end

  def max_count
    return @count_list.max
  end

  def next_index
    count_max_over = max_count + 1
    min = (0...@size).min_by do |i|
      @level_list[i] * count_max_over - @count_list[i]
    end
    return min
  end

  def level_up(i, exp)
    @count_list[i] += 1
    @level_list[i] += exp
  end
end

gets
own = OwnParty.new(gets.split.map(&:to_i))
mon = Party.new(gets.split.map(&:to_i))
list = (0..mon.size).map do |i|
  own_c = own.clone
  mon.level_each_with_start_pos(i) do |level|
    own_c.level_up(own_c.next_index, level / 2)
  end
  own_c.max_count
end
puts list.min
0