結果

問題 No.955 ax^2+bx+c=0
ユーザー trineutrontrineutron
提出日時 2019-12-07 17:25:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,166 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 166,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 23:29:25
合計ジャッジ時間 4,347 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 109 WA * 13
権限があれば一括ダウンロードができます

ソースコード

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