結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー |
![]() |
提出日時 | 2020-02-20 21:12:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 1,066 ms |
コンパイル使用メモリ | 89,036 KB |
最終ジャッジ日時 | 2025-01-09 01:11:08 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
#include <iostream> #include <cmath> #include <iomanip> using namespace std; using ll = long long; int main() { ll a, b, c; cin >> a >> b >> c; if (a < 0) { a *= -1; b *= -1; c *= -1; } if (a == b && b == c && c == 0) { cout << -1 << endl; return 0; } cout << fixed << setprecision(20); if (a == 0) { if (b == 0) { cout << 0 << endl; return 0; } cout << 1 << endl; cout << (double)-c / b << endl; return 0; } ll D = b * b - 4 * a * c; if (D < 0) { cout << 0 << endl; return 0; } if (D == 0) { cout << 1 << endl; cout << (double)(-b) / (2 * a) << endl; return 0; } if (b > 0) { cout << 2 << endl; long double x1 = (-b - sqrt(D)) / (2 * a); cout << x1 << endl; cout << (double)c / a / x1 << endl; } else { cout << 2 << endl; long double x1 = (-b + sqrt(D)) / (2 * a); cout << (double)c / a / x1 << endl; cout << x1 << endl; } return 0; }