結果

問題 No.40 多項式の割り算
ユーザー d_nishiyama85d_nishiyama85
提出日時 2016-07-17 11:12:29
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 544 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 104,772 KB
最終ジャッジ日時 2024-04-23 14:55:46
合計ジャッジ時間 13,355 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
12,288 KB
testcase_01 AC 102 ms
12,416 KB
testcase_02 AC 101 ms
12,416 KB
testcase_03 AC 102 ms
12,416 KB
testcase_04 AC 2,405 ms
72,448 KB
testcase_05 AC 3,860 ms
78,208 KB
testcase_06 TLE -
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:23: warning: assigned but unused variable - d
Syntax OK

ソースコード

diff #

require 'pp'

def divide(poly, div, q)
  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

  return [_poly, q]
end

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

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

while div.length <= poly.length
  poly, q = divide(poly, div, q)
end

if poly.empty?
  puts 0
  puts 0
else
  puts (poly.length - 1)
  puts poly.join(' ')
end
0