結果

問題 No.955 ax^2+bx+c=0
ユーザー koba-e964
提出日時 2019-12-18 00:24:16
言語 Ruby
(3.4.1)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-18 21:58:02
合計ジャッジ時間 14,873 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a,b,c=gets.split.map &:to_i
if a==0
  if b==0
    if c==0
      puts (-1)
    else
      puts 0
    end
    exit
  end
  puts 1
  printf "%.15f\n", (-c/1.0/b)
  exit
end

if a<0
  a=-a
  b=-b
  c=-c
end
d=b*b-4*a*c
if d==0
  puts 1
  printf "%.15f\n", (-b/2.0/a)
  exit
end
if d<0
  puts 0
  exit
end
puts 2
s=Math.sqrt(d)/(2.0*a).abs
t=Math.sqrt(d)
if b >= 0
  printf "%.15f\n", (-b/(2.0*a)-s)
else
  printf "%.15f\n", (2.0*c/(-b+t))
end
if b <= 0
  printf "%.15f\n", (-b/(2.0*a)+s)
else
  printf "%.15f\n", (2.0*c/(-b-t))
end
0