結果

問題 No.955 ax^2+bx+c=0
ユーザー 草苺奶昔
提出日時 2023-02-27 18:45:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 66,560 KB
最終ジャッジ日時 2024-09-15 01:15:51
合計ジャッジ時間 12,056 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from typing import List, Tuple


def quadratic_solver(A: int, B: int, C: int) -> 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 - sqrt(D)) / (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(int, input().split())
    n, res = quadratic_solver(a, b, c)
    if n == -1:
        print(-1)
    else:
        print(n)
        for x in res:
            print(x)
0