結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
![]() |
提出日時 | 2020-04-17 20:51:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 825 bytes |
コンパイル時間 | 583 ms |
コンパイル使用メモリ | 58,936 KB |
最終ジャッジ日時 | 2025-01-09 19:38:36 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
コンパイルメッセージ
main.cpp: In function ‘int solve_testcase()’: main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%jd %jd %jd", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <cstdint> #include <cmath> #include <algorithm> #include <utility> int solve_testcase() { intmax_t a, b, c; scanf("%jd %jd %jd", &a, &b, &c); if (a != 0) { if (b < 0) { a = -a; b = -b; c = -c; } __int128 d = b*b - __int128(4)*a*c; if (d < 0) return puts("0"), 0; if (d == 0) return !printf("1\n%.12Lf\n", (-b / (2.0L*a))); long double sd = std::sqrt(b*b - 4.0L*a*c); long double x1 = (-2.0L*c) / (b + sd); long double x2 = (b + sd) / (-2.0L*a); if (x1 > x2) std::swap(x1, x2); return !printf("2\n%.12Lf\n%.12Lf\n", x1, x2); } if (b != 0) { long double x = -1.0L * c / b; return !printf("1\n%.12Lf\n", x); } if (c != 0) return puts("0"), 0; return puts("-1"), 0; } int main() { solve_testcase(); }