結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2019-12-07 18:42:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,371 bytes |
| コンパイル時間 | 1,380 ms |
| コンパイル使用メモリ | 167,248 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 23:30:32 |
| 合計ジャッジ時間 | 3,556 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 120 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int64_t a, b, c, det;
double f(double x) {
double plus = 0.0, minus = 0.0;
if (a >= 0) {
plus += a;
} else {
minus += a;
}
plus *= x;
minus *= x;
if (b * x >= 0) {
plus += b;
} else {
minus += b;
}
plus *= x;
minus *= x;
if (c >= 0) {
plus += c;
} else {
minus += c;
}
return plus + minus;
}
int main() {
cin >> a >> b >> c;
assert(-1000000000 <= a && a <= 1000000000);
assert(-1000000000 <= b && b <= 1000000000);
assert(-1000000000 <= c && c <= 1000000000);
det = b * b - 4 * a * c;
cout << setprecision(17);
if (a == 0) {
if (b == 0) {
if (c == 0) {
cout << -1 << endl;
} else {
cout << 0 << endl;
}
} else {
cout << 1 << endl;
cout << (double) -c / b << endl;
}
} else {
if (det < 0) {
cout << 0 << endl;
} else if (det == 0) {
cout << 1 << endl;
cout << (double) -b / (2 * a) << endl;
} else {
cout << 2 << endl;
double lower_bound = -10000000000, upper_bound = (double) -b / (2 * a);
while (lower_bound < upper_bound) {
double half = (lower_bound + upper_bound) / 2;
if (f(lower_bound) == 0) break;
if (f(lower_bound) * f(half) < 0) {
if (upper_bound == half) break;
upper_bound = half;
} else {
if (lower_bound == half) break;
lower_bound = half;
}
}
cout << lower_bound << endl;
lower_bound = (double) -b / (2 * a);
upper_bound = 10000000000;
while (lower_bound < upper_bound) {
double half = (lower_bound + upper_bound) / 2;
if (f(lower_bound) == 0) break;
if (f(lower_bound) * f(half) < 0) {
if (upper_bound == half) break;
upper_bound = half;
} else {
if (lower_bound == half) break;
lower_bound = half;
}
}
cout << lower_bound << endl;
}
}
}
trineutron