結果

問題 No.955 ax^2+bx+c=0
ユーザー CELICA
提出日時 2020-09-15 23:18:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 172,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 02:50:09
合計ジャッジ時間 4,197 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll a, b, c;
	cin >> a >> b >> c;

	int res{ 0 };
	vector<long double> ans;
	ll d = b * b - 4 * a * c;
	if (a)
	{
		if (d < 0)
			;
		else if (d == 0)
		{
			res = 1;
			ans.push_back(-b / (a * 2.0));
		}
		else
		{
			res = 2;
			long double aa, bb, cc, dd;
			if (b > 0)
			{
				aa = a;
				bb = b;
				cc = c;
			}
			else
			{
				aa = -a;
				bb = -b;
				cc = -c;
			}

			dd = sqrt((long double)d);
			long double a1, a2;
			a1 = -(bb + dd) / (2.0 * aa);
			a2 = -(2.0 * cc) / (bb + dd);
			ans.push_back(min(a1, a2));
			ans.push_back(max(a1, a2));
		}
	}
	else if (b)
	{
		res = 1;
		ans.push_back(c ? -(long double)c / b : 0);
	}
	else if (c)
		res = 0;
	else
		res = -1;

	cout << res << "\n";
	if (res)
	{
		for (int i = 0; i < res; ++i)
			cout << setprecision(17) << ans[i] << "\n";
	}

	return 0;
}
0