結果

問題 No.550 夏休みの思い出(1)
ユーザー minamiminami
提出日時 2017-07-28 22:48:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,292 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 178,708 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 13:08:33
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 0 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,948 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 1 ms
6,948 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 1 ms
6,940 KB
testcase_38 AC 1 ms
6,944 KB
testcase_39 AC 1 ms
6,944 KB
testcase_40 AC 1 ms
6,940 KB
testcase_41 AC 1 ms
6,944 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 1 ms
6,944 KB
testcase_45 AC 1 ms
6,944 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 1 ms
6,944 KB
testcase_52 AC 1 ms
6,940 KB
testcase_53 AC 1 ms
6,940 KB
testcase_54 AC 1 ms
6,944 KB
testcase_55 AC 1 ms
6,940 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using ld = long double;
const double eps = 1e-8;

ld bisection_method(ld x0, ld x1, std::function<ld(ld)> f) {
	ld y0 = f(x0), y1 = f(x1), m;
	int s0 = std::abs(y0) < eps ? 0 : y0 < 0 ? -1 : 1;
	int s1 = std::abs(y1) < eps ? 0 : y1 < 0 ? -1 : 1;
	assert(s0 * s1 <= 0);
	if (y0 > y1) std::swap(x0, x1);
	for (int i = 0; i < 200; i++) {
		m = (x0 + x1) / 2;
		if (f(m) > 0)
			x1 = m;
		else
			x0 = m;
	}
	return m;
}

std::vector<ld> quadratic_equation(ld a, ld b, ld c) {
	ld d = b * b - 4 * a * c;
	if (std::abs(a) < eps) return std::abs(b) > eps ? std::vector<ld>{-c / b} : std::vector<ld>{};
	if (d < -eps) return{};
	if (d < eps) return{ -b / (2 * a), -b / (2 * a) };
	int sign = (b >= 0) ? 1 : -1;
	ld x0 = (-b - sign * sqrt(std::abs(d))) / (2 * a), x1 = c / (a * x0);
	if (x0 > x1) std::swap(x0, x1);
	return{ x0, x1 };
}

std::vector<ld> cubic_equation(ld a, ld b, ld c, ld d) {
	if (std::abs(a) < eps) return quadratic_equation(b, c, d);
	if (a < 0) a = -a, b = -b, c = -c, d = -d;
	static const ld INF = 1e9;
	ld x0 =
		bisection_method(-INF, INF, [&](ld x) { return a * x * x * x + b * x * x + c * x + d; });
	ld aa = 1, bb = b / a + x0, cc = c / a + bb * x0;
	auto res = quadratic_equation(aa, bb, cc);
	res.push_back(x0);
	std::sort(res.begin(), res.end());
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	auto w = cubic_equation(1, a, b, c);
	sort(all(w));
	vector<int> v;
	rep(i, -1, 2) {
		rep(j, 0, 3) {
			int x = w[j] + i;
			if (x*x*x + a*x*x + b*x + c == 0)
				v.push_back(x);
		}
	}
	sort(all(v));
	v.erase(unique(v.begin(), v.end()), v.end());
	cout << v[0]; rep(i, 1, v.size()) { cout << " " << v[i]; } cout << endl;
	return 0;
}
0