結果

問題 No.955 ax^2+bx+c=0
ユーザー totori_nyaa
提出日時 2020-02-28 02:35:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 167,256 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 16:17:52
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 93 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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


bool chmax(int &a,int b){
    if(a<b){
        a = b;
        return 1;
    }
    return 0;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    
    
    long double a,b,c;
    cin>>a>>b>>c;
    if(a==0 && b==0){
        if(c)cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(a==0){
        cout << 1 << endl;
        cout << (long double)(-c/b) << endl;
        return 0;
    }
    double ans1,ans2;
    if(b*b < 4*a*c){
        cout << 0 << endl;
        return 0;
    }
    if(b*b == 4*a*c){
        cout << 1 << endl;
        double ans = (long double)(-b / (2.0*a));
        cout << ans << endl;
        return 0;
    }
    cout << 2 << endl;
    long double t = b*b - 4.0*a*c;
    long double low = 0.0,up=1e9;
    int cnt = 0;
    while(cnt < 1050){
        cnt++;
        long double mid = (up+low)/2.0;
        if(mid*mid > t) up = mid;
        else low = mid;
    }
    long double j = low;
    ans1 = (long double)( -b + j);
    ans2 = (long double)( -b - j);
    ans1 /= (long double)2.0*a;
    ans2 /= (long double)2.0*a;
    if(a<0) swap(ans1,ans2);
    cout << ans2 << endl;
    cout << ans1 << endl;
    return 0;

}
0