結果

問題 No.1179 Quadratic Equation
ユーザー trineutrontrineutron
提出日時 2020-08-21 21:27:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 192,604 KB
最終ジャッジ日時 2025-01-13 05:04:40
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t a, b, c, det;
    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) {
    } else {
        if (det < 0) {
            cout << "imaginary" << endl;
        } else if (det == 0) {
            cout << (double) -b / (2 * a) << endl;
        } else {
            double s = sqrt((double) det);
            if (b > 0) {
                double x1 = (-b - s) / (2 * a), x2 = (2 * c) / (-b - s);
                cout << min(x1, x2) << " ";
                cout << max(x1, x2) << endl;
            } else {
                double x1 = (2 * c) / (-b + s), x2 = (-b + s) / (2 * a);
                cout << min(x1, x2) << " ";
                cout << max(x1, x2) << endl;
            }
        }
    }
}
0