結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
りあん
|
| 提出日時 | 2022-03-02 23:27:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,649 bytes |
| コンパイル時間 | 2,449 ms |
| コンパイル使用メモリ | 198,052 KB |
| 最終ジャッジ日時 | 2025-01-28 04:20:52 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 121 WA * 1 |
ソースコード
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using fltype = long double;
using itype = long long;
vector<fltype> quadratic_equation(itype a, itype b, itype c) {
assert(abs(a) <= (1 << 30) && abs(b) <= (1 << 30) && abs(c) <= (1 << 30));
if (a) {
if (a < 0) {
a = -a;
b = -b;
c = -c;
}
itype d = b * b - 4 * a * c;
if (d > 0) {
if (b > 0) {
fltype x1 = (-b - sqrt((fltype)d)) / (2 * a);
fltype x2 = c / (fltype)a / x1;
assert(x1 <= x2);
return { x1, x2 };
}
else {
fltype x2 = (-b + sqrt((fltype)d)) / (2 * a);
fltype x1 = c / (fltype)a / x2;
assert(x1 <= x2);
return { x1, x2 };
}
}
else if (d == 0) {
return { -b / (fltype)(2 * a) };
}
else {
return {};
}
}
else if (b) {
return { -c / (fltype)b };
}
else if (c) {
return {};
}
else {
// represents infinite
return {-1, -1, -1};
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
itype a, b, c;
cin >> a >> b >> c;
vector<fltype> res = quadratic_equation(a, b, c);
cout << setprecision(16);
if (res.size() == 3) {
cout << 0 << '\n';
}
else {
cout << res.size() << '\n';
for (auto& i : res) {
cout << i << '\n';
}
}
return 0;
}
りあん