結果

問題 No.955 ax^2+bx+c=0
ユーザー renfukatsu
提出日時 2020-06-04 23:01:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 166,892 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 18:21:45
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve(ld a, ld b, ld c)
{
    // 判別式
    ld D = b*b - 4.0L*a*c;
    cout << fixed << setprecision(15);
    if(a==0 && b == 0 && c==0)
    {
        cout << "-1\n";
    }
    else if((a==0 && b==0) || D<0)
    {
        cout << "0\n";
    }
    else if(a==0)
    {
        // x = -c/b | a==0
        cout << "1\n" << -c/b << '\n';
    }
    else if(D==0)
    {
        // x = -b / 2a
        cout << "1\n" << -b/(2.0L*a) << '\n';
    }
    else
    {
        ld x1 = (-b + sqrt(D)) / (2.0L * a);
        ld x2 = (-b - sqrt(D)) / (2.0L * a);
        cout << "2\n" << min(x1, x2) << '\n' << max(x1, x2) << '\n';
    }
    
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    solve(a, b, c);

    return 0;
}
0