結果

問題 No.955 ax^2+bx+c=0
ユーザー trineutrontrineutron
提出日時 2019-11-09 18:04:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 168,072 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 23:28:34
合計ジャッジ時間 4,153 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 102 WA * 20
権限があれば一括ダウンロードができます

ソースコード

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