結果

問題 No.955 ax^2+bx+c=0
ユーザー bluemegane
提出日時 2021-05-13 06:59:03
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 2,488 ms
コンパイル使用メモリ 112,252 KB
実行使用メモリ 27,200 KB
最終ジャッジ日時 2024-09-24 19:41:01
合計ジャッジ時間 7,168 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 108 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var c = long.Parse(line[2]);
        if (a >= 0) getAns(a, b, c);
        else getAns(-a, -b, -c);
    }
    static void getAns(long a, long b, long c)
    {
        var ans = 0d;
        if (a == 0 && b == 0 && c == 0) { Console.WriteLine(-1); return; }
        if (a == 0 && b == 0 && c != 0) { Console.WriteLine(0); return; }
        var D = b * b - 4L * a * c;
        if (a != 0 && D == 0)
        {
            Console.WriteLine(1);
            ans = -b / 2d / a;
            Console.WriteLine(ans);
            return;
        }
        if (a != 0 && D > 0)
        {
            Console.WriteLine(2);
            var t = Sqrt(D);
            if (b > 0)
            {
                var ans1 = (-b - t) / 2d / a;
                var ans2 = c / a / ans1;
                Console.WriteLine(Min(ans1, ans2));
                Console.WriteLine(Max(ans1, ans2));
            }
            else
            {
                var ans1 = (-b + t) / 2d / a;
                var ans2 = c / a / ans1;
                Console.WriteLine(Min(ans1, ans2));
                Console.WriteLine(Max(ans1, ans2));
            }
            return;
        }
        if (a != 0 && D < 0)
        {
            Console.WriteLine(0);
            return;
        }
        if (a == 0 && b != 0)
        {
            Console.WriteLine(1);
            ans = -(double)c / b;
            Console.WriteLine(ans);
            return;
        }
    }
}
0