結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
![]() |
提出日時 | 2022-03-02 23:28:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,650 bytes |
コンパイル時間 | 2,054 ms |
コンパイル使用メモリ | 197,780 KB |
最終ジャッジ日時 | 2025-01-28 04:21:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
// #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 << -1 << '\n'; } else { cout << res.size() << '\n'; for (auto& i : res) { cout << i << '\n'; } } return 0; }