結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
![]() |
提出日時 | 2021-04-11 17:12:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,381 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-06-27 11:55:24 |
合計ジャッジ時間 | 7,116 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] dij = [(0, 1), (1, 0), (1, 1), (1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 from decimal import * a, b, c = map(Decimal, SI().split()) # 問題で「方程式」って言ってるから本当はa=b=0はナシだと思うけど念の為 if a == b == 0: if c == 0: print(-1) else: print(0) elif a == 0: ans = -c/b print(1) print(ans) elif b**2-4*a*c > 0: a0 = (-b-(b**2-4*a*c).sqrt())/(2*a) a1 = (-b+(b**2-4*a*c).sqrt())/(2*a) if a0 > a1: a0, a1 = a1, a0 print(2) print(f"{a0:.12f}") print(f"{a1:.12f}") elif b**2-4*a*c == 0: a0 = -b/(2*a) print(1) print(f"{a0:.12f}") else: print(0)