結果

問題 No.40 多項式の割り算
ユーザー d_nishiyama85d_nishiyama85
提出日時 2016-07-17 11:02:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 523 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 581,248 KB
最終ジャッジ日時 2024-04-23 14:54:14
合計ジャッジ時間 14,288 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 89 ms
12,160 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 MLE -
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 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: assigned but unused variable - d
Main.rb:29: warning: assigned but unused variable - q
Syntax OK

ソースコード

diff #

def divide(poly, div, q)
  if poly.length < div.length
    return [q.reverse, poly]
  end
  c = poly[-1] / div[-1]
  q << c
  _poly = []
  _div = div.clone

  while _div.length < poly.length
    _div.unshift(0)
  end

  poly.length.times{|d|
    _poly[d] = poly[d] - c * _div[d]
  }
  while _poly[-1] == 0
    _poly.pop()
  end

  divide(_poly, div, q)
end

d = gets.to_i
as = gets.strip.split.map{|e| e.to_i}

div = [0, -1, 0, 1]

q, r = divide(as, div, [])

puts r.length

if r.empty?
  puts 0
else
  puts r.join(' ')
end
0