結果

問題 No.955 ax^2+bx+c=0
コンテスト
ユーザー bal4u
提出日時 2019-12-18 15:56:31
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 868 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 210 ms
コンパイル使用メモリ 50,688 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-28 14:59:57
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yuki 955 ax^2+bx+c=0
// 2019.12.18 bal4u

#include <stdio.h>
#include <math.h>

typedef long long ll;

long double mySqrt(ll x)
{
	long double s, last;

	if (x <= 0) return 0;
	if (x > 1) s = x;
	else s = 1;
	do {
		last = s;
		s = (x / s + s) * 0.5;
	} while (s < last);
	return last;
}

int main()
{
	int a, b, c;
	long double x1, x2;

	scanf("%d%d%d", &a, &b, &c);
	if (a == 0) {
		if (b == 0 && c == 0) puts("-1");
		else if (b == 0) puts("0");
		else {
			puts("1");
			printf("%.16lf\n", -(double)c/b);
		}
	} else {
		ll d = (ll)b*b - 4*(ll)a*c;
		if (d < 0) puts("0");
		else if (d == 0) {
			puts("1");
			printf("%.16lf\n", -(double)b/(2*a));
		} else {
			long double t = mySqrt(d);
			puts("2");
			x1 = (-b-t)/(2*a), x2 = (-b+t)/(2*a);
			if (x1 <= x2) printf("%.16Lf\n%.16Lf\n", x1, x2);
			else printf("%.16Lf\n%.16Lf\n", x2, x1);
		}
	}
	return 0;
}
0