結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
yuruhiya
|
| 提出日時 | 2019-12-21 23:17:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 910 bytes |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 193,340 KB |
| 最終ジャッジ日時 | 2025-01-08 13:48:41 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 122 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
cin >> a >> b >> c;
long double A = a, B = b, C = c;
cout << fixed << setprecision(18);
if (a == 0 && b == 0 && c == 0) {
cout << -1 << endl;
} else if (a == 0 && b == 0) {
cout << 0 << endl;
} else if (a == 0) {
cout << 1 << endl;
cout << -(C / B) << endl;
} else {
long long d = b * b - 4 * a * c;
long double D = static_cast<long double>(d);
if (d < 0) {
cout << 0 << endl;
} else if (d == 0) {
cout << 1 << endl;
cout << -B / (2 * A) << endl;
} else {
cout << 2 << endl;
long double ans1 = 0, ans2 = 0;
if (b > 0) {
ans1 = (-B - sqrt(D)) / (2 * A);
} else {
ans1 = (-B + sqrt(D)) / (2 * A);
}
ans2 = (C / A) / ans1;
cout << min(ans1, ans2) << endl;
cout << max(ans1, ans2) << endl;
}
}
}
yuruhiya