結果

問題 No.955 ax^2+bx+c=0
ユーザー siman
提出日時 2022-09-14 02:32:13
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 411 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-12-14 10:44:25
合計ジャッジ時間 14,753 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84 WA * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

A, B, C = gets.split.map(&:to_i)

if A == 0 && B == 0
  puts -1
elsif A == 0
  puts 1
  puts "%.12f" % Rational(-C, B)
else
  e = B ** 2 - 4 * A * C

  if e == 0
    puts 1
    puts "%.12f" % Rational(-B, 2 * A)
  elsif e < 0
    puts 0
  else
    puts 2
    x = Rational(-B - Math.sqrt(e), 2 * A)
    y = Rational(-B + Math.sqrt(e), 2 * A)
    puts "%.12f" % [x, y].min
    puts "%.12f" % [x, y].max
  end
end
0