結果

問題 No.40 多項式の割り算
ユーザー letrangerjpletrangerjp
提出日時 2017-06-14 22:03:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 339 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 11,972 KB
実行使用メモリ 16,828 KB
最終ジャッジ日時 2023-10-25 03:50:42
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
16,200 KB
testcase_01 AC 83 ms
16,200 KB
testcase_02 AC 83 ms
16,200 KB
testcase_03 AC 84 ms
16,200 KB
testcase_04 AC 100 ms
16,560 KB
testcase_05 AC 104 ms
16,640 KB
testcase_06 AC 111 ms
16,824 KB
testcase_07 AC 116 ms
16,828 KB
testcase_08 AC 87 ms
16,200 KB
testcase_09 AC 104 ms
16,636 KB
testcase_10 AC 109 ms
16,756 KB
testcase_11 AC 98 ms
16,536 KB
testcase_12 AC 93 ms
16,424 KB
testcase_13 AC 110 ms
16,752 KB
testcase_14 AC 101 ms
16,560 KB
testcase_15 AC 104 ms
16,564 KB
testcase_16 AC 109 ms
16,752 KB
testcase_17 AC 93 ms
16,356 KB
testcase_18 AC 111 ms
16,748 KB
testcase_19 AC 113 ms
16,828 KB
testcase_20 AC 98 ms
16,528 KB
testcase_21 AC 92 ms
16,344 KB
testcase_22 AC 89 ms
16,340 KB
testcase_23 AC 97 ms
16,528 KB
testcase_24 AC 104 ms
16,640 KB
testcase_25 AC 84 ms
16,200 KB
testcase_26 AC 85 ms
16,200 KB
testcase_27 AC 85 ms
16,200 KB
testcase_28 AC 84 ms
16,196 KB
testcase_29 AC 84 ms
16,200 KB
testcase_30 AC 84 ms
16,200 KB
testcase_31 AC 84 ms
16,200 KB
testcase_32 AC 86 ms
16,196 KB
testcase_33 AC 85 ms
16,200 KB
testcase_34 AC 84 ms
16,200 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

M = [-1, 0, 1]
D = gets.to_i
A = gets.split.take(D + 1).map(&:to_i)


def f(a, m)
  res = []
  while a.size > m.size
    n = a[-1].quo(m[-1])
    res.unshift(n)
    (-m.size..-1).each{|i|
      a[i] -= n * m[i]
    }
    a.pop
  end
  a
end

ans = f(A, M)
take = ans.rindex{|v|v != 0} || 0
p take
puts ans.take(take + 1).map(&:to_i) * " "
0