結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
![]() |
提出日時 | 2022-09-14 02:45:40 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-12-14 11:00:12 |
合計ジャッジ時間 | 14,328 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
コンパイルメッセージ
Main.rb:4: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
A, B, C = gets.split.map(&:to_i) if A == 0 && B == 0 && C == 0 puts -1 elsif A == 0 && B == 0 puts 0 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 = if B > 0 Rational(-B - Math.sqrt(e), 2 * A) else Rational(-B + Math.sqrt(e), 2 * A) end y = Rational(C, A * x) puts "%.12f" % [x, y].min puts "%.12f" % [x, y].max end end