結果
| 問題 |
No.550 夏休みの思い出(1)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:53:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,396 bytes |
| コンパイル時間 | 173 ms |
| コンパイル使用メモリ | 82,648 KB |
| 実行使用メモリ | 62,500 KB |
| 最終ジャッジ日時 | 2025-03-20 20:54:10 |
| 合計ジャッジ時間 | 4,632 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
import math
def find_roots(A, B, C):
if C == 0:
roots = [0]
D = A * A - 4 * B
if D >= 0:
sqrtD = int(math.isqrt(D))
if sqrtD * sqrtD == D:
x1 = (-A - sqrtD) // 2
x2 = (-A + sqrtD) // 2
roots.extend([x1, x2])
roots = sorted(list(set(roots)))
return roots[:3] if len(roots) > 3 else roots
def possible_p(C_val):
k = abs(C_val)
if k == 0:
yield 0
return
max_i = int(math.isqrt(k)) + 1
seen = set()
for i in range(1, max_i + 1):
if k % i == 0:
for d in (i, k // i):
if d not in seen:
seen.add(d)
if d <= 1e9:
yield d
yield -d
p_found = None
for p in possible_p(C):
if p**3 + A * p**2 + B * p + C == 0:
p_found = p
break
d = A + p_found
e = (B + p_found * d)
D = d * d - 4 * e
if D < 0:
return []
sqrtD = int(math.isqrt(D))
if sqrtD * sqrtD != D:
return []
x1 = (-d - sqrtD) // 2
x2 = (-d + sqrtD) // 2
roots = [p_found, x1, x2]
roots = sorted(roots)
return roots
A, B, C = map(int, input().split())
roots = find_roots(A, B, C)
print(' '.join(map(str, roots)))
lam6er