結果

問題 No.40 多項式の割り算
ユーザー siman
提出日時 2015-04-02 00:16:10
言語 Ruby
(3.4.1)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 435 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-07-03 23:12:58
合計ジャッジ時間 3,986 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class A
  def initialize
    d = gets.chomp.to_i
    a = gets.chomp.split(' ').map(&:to_i).reverse

    0.upto(d-3) do |num|
      a[num+2] += a[num]
      a[num] = 0
    end

    if a.index{|i| i != 0}
      puts d - a.index{|i| i != 0}
    else
      puts 0
    end

    if a.index(&:nonzero?).nil?
      puts 0
    else
      a = a[a.index(&:nonzero?)..-1]
      puts (a.size.zero?)? 0 : a.reverse.join(' ')
    end
  end
end

A.new
0