結果

問題 No.40 多項式の割り算
ユーザー cielciel
提出日時 2014-11-16 22:03:41
言語 Ruby
(3.4.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 420 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 94,592 KB
最終ジャッジ日時 2024-12-31 21:25:53
合計ジャッジ時間 69,943 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 TLE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
ruby: warning: shebang line ending with \r may cause problems
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby

def sub(a,b)
	m=[a.size,b.size].max
	m.times.map{|i|(a[i]||0) - (b[i]||0)}
end

def checkio(exp,div)
	c=[]
	while div.size<=exp.size
		d=exp[-1]/div[-1]
		c.push(d)
		exp=sub(exp,[0]*(exp.size-div.size)+div.map{|e|e*d})
		#assert exp[-1]==0
		exp.pop
	end
	exp.pop() while exp.size>1 && exp[-1]==0
	puts exp.size-1
	puts exp*' '
end

gets
checkio(gets.split.map(&:to_i),[0,-1,0,1])
0