結果

問題 No.955 ax^2+bx+c=0
ユーザー 草苺奶昔
提出日時 2023-02-27 18:39:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 932 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 69,248 KB
最終ジャッジ日時 2024-09-15 01:12:14
合計ジャッジ時間 11,169 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 97 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Tuple


def quadratic_solver(A: float, B: float, C: float) -> Tuple[int, List[float]]:
    """A*x^2 + B*x + C = 0

    返回解的个数和解的列表(-1表示无穷多个解)
    """
    if B < 0:
        A = -A
        B = -B
        C = -C
    if A == 0:
        if B == 0:
            if C == 0:
                return -1, []  # 无穷多个解
            return 0, []  # 无解
        return 1, [-C / B]

    D = B * B - 4 * A * C
    if D < 0:
        return 0, []
    if D == 0:
        return 1, [-B / (2 * A)]
    res1 = (-B - D**0.5) / (2 * A)
    res2 = C / A / res1
    if res1 > res2:
        res1, res2 = res2, res1
    return 2, [res1, res2]


if __name__ == "__main__":
    # https://yukicoder.me/problems/no/955%3E
    a, b, c = map(float, input().split())
    n, res = quadratic_solver(a, b, c)
    if n == -1:
        print(-1)
        exit(0)
    print(n)
    print(*res, sep="\n")
0