結果

問題 No.955 ax^2+bx+c=0
ユーザー face4face4
提出日時 2019-12-18 18:28:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 843 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 00:51:42
合計ジャッジ時間 2,793 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 96 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#define equals(a,b) (fabs(a-b) < 1e-13)

int main(){
    cout << fixed << setprecision(15);
    long double a, b, c;
    cin >> a >> b >> c;
    if(a == 0){
        if(b == 0){
            cout << (c==0 ? -1 : 0) << endl;
        }else{
            cout << 1 << endl << -c/b << endl;
        }
    }else{
        long double d = b*b-4*a*c;
        if(d < 0){
            cout << 0 << endl;
        }else if(equals(d,0)){
            cout << 1 << endl << -b/a/2 << endl;
        }else{
            long double f = sqrt(d);
            // :(
            long double x = (-b + (b<0 ? f : -f))/2/a;
            long double y = c/x;
            if(x > y)   swap(x,y);
            cout << 2 << endl;
            cout << x << endl << y << endl;
        }
    }
    return 0;
}
0