結果

問題 No.40 多項式の割り算
ユーザー DialBird
提出日時 2017-02-13 10:24:26
言語 Ruby
(3.4.1)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 569 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-12-29 17:36:17
合計ジャッジ時間 4,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Solve
  def initialize
    _ = gets.to_i
    @a_list = gets.chomp.split.map(&:to_i)
  end

  def run
    len = @a_list.size
    (len - 1).downto(3) do |i|
      if @a_list[i] != 0
        @a_list[i-2] += @a_list[i]
        @a_list[i] = 0
      end
    end

    puts get_ans_list[0]
    puts get_ans_list[1]
  end

  private

  def get_ans_list
    list = []
    3.downto(0) do |i|
      if (@a_list[i] != 0 && @a_list[i] != nil) || i == 0
        list << i
        list << @a_list[0..i].join(' ')
        break
      end
    end

    list
  end
end

Solve.new.run
0