結果

問題 No.550 夏休みの思い出(1)
ユーザー sora410_tsora410_t
提出日時 2017-11-02 22:15:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 86,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 15:52:49
合計ジャッジ時間 7,871 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
4,376 KB
testcase_01 AC 69 ms
4,380 KB
testcase_02 AC 69 ms
4,376 KB
testcase_03 AC 70 ms
4,380 KB
testcase_04 AC 69 ms
4,384 KB
testcase_05 AC 71 ms
4,380 KB
testcase_06 AC 70 ms
4,380 KB
testcase_07 AC 69 ms
4,380 KB
testcase_08 AC 70 ms
4,380 KB
testcase_09 AC 71 ms
4,380 KB
testcase_10 AC 71 ms
4,376 KB
testcase_11 AC 70 ms
4,376 KB
testcase_12 AC 70 ms
4,380 KB
testcase_13 AC 48 ms
4,380 KB
testcase_14 AC 59 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 46 ms
4,380 KB
testcase_17 AC 51 ms
4,376 KB
testcase_18 AC 63 ms
4,376 KB
testcase_19 AC 47 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 54 ms
4,376 KB
testcase_23 AC 35 ms
4,380 KB
testcase_24 AC 38 ms
4,376 KB
testcase_25 AC 44 ms
4,380 KB
testcase_26 AC 42 ms
4,380 KB
testcase_27 AC 36 ms
4,380 KB
testcase_28 AC 38 ms
4,380 KB
testcase_29 AC 29 ms
4,380 KB
testcase_30 AC 61 ms
4,376 KB
testcase_31 AC 47 ms
4,376 KB
testcase_32 AC 48 ms
4,380 KB
testcase_33 AC 70 ms
4,380 KB
testcase_34 AC 53 ms
4,380 KB
testcase_35 AC 63 ms
4,376 KB
testcase_36 AC 62 ms
4,376 KB
testcase_37 AC 55 ms
4,376 KB
testcase_38 AC 68 ms
4,380 KB
testcase_39 AC 22 ms
4,380 KB
testcase_40 AC 28 ms
4,376 KB
testcase_41 AC 23 ms
4,376 KB
testcase_42 AC 25 ms
4,376 KB
testcase_43 AC 20 ms
4,376 KB
testcase_44 AC 20 ms
4,376 KB
testcase_45 AC 20 ms
4,380 KB
testcase_46 AC 21 ms
4,380 KB
testcase_47 AC 15 ms
4,376 KB
testcase_48 AC 7 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 52 ms
4,376 KB
testcase_53 AC 57 ms
4,376 KB
testcase_54 AC 52 ms
4,376 KB
testcase_55 AC 55 ms
4,380 KB
testcase_56 AC 66 ms
4,384 KB
testcase_57 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

vector<__int64_t> giveDivisor(const __int64_t c) noexcept {
	vector<__int64_t> divs;
	if (c == 0) { return {0}; }
	const __int64_t abs_c = abs(c);
	for (__int64_t i = 1; i <= pow(abs_c, 1.0/3.0); ++i) {
		if (abs_c % i == 0) {
			divs.push_back(i);
			divs.push_back(-1*i);
			divs.push_back(abs_c/i);
			divs.push_back(-1*(abs_c/i));
		}
	}
	return divs;
}

tuple<__int64_t, __int64_t> syntheticDivision(const __int64_t a, const __int64_t b, const __int64_t c, const __int64_t x1) noexcept {
	return make_tuple(a + x1, b + x1 * (a + x1));
}

tuple<__int64_t, __int64_t> solve2d(const __int64_t a, const __int64_t b) noexcept {
	const __int64_t x2 = (-1 * a + sqrt(a*a - 4*b)) / 2;
	const __int64_t x3 = (-1 * a - sqrt(a*a - 4*b)) / 2;
	return make_tuple(x2, x3);
}

tuple<__int64_t, __int64_t, __int64_t> sort_ans(const __int64_t a, const __int64_t b, const __int64_t c) noexcept {
	vector<__int64_t> tmp {a, b, c};
	sort(tmp.begin(), tmp.end());
	return make_tuple(tmp[0], tmp[1], tmp[2]);
}

tuple<__int64_t, __int64_t, __int64_t> solve3d(const __int64_t a, const __int64_t b, const __int64_t c) noexcept {
	auto f = [a, b, c](const __int64_t x) { return x*x*x + a*x*x + b*x + c; };
	for (const __int64_t x : giveDivisor(c)) {
		if (f(x) == 0) {
			const __int64_t x1 = x;
			__int64_t a2, b2, x2, x3;
			tie(a2, b2) = syntheticDivision(a, b, c, x1);
			tie(x2, x3) = solve2d(a2, b2);
			return sort_ans(x1, x2, x3);
		}
	}
	return make_tuple(0, 0, 0);
}

int main() {
	__int64_t a, b, c;
	cin >> a >> b >> c;
	__int64_t x1, x2, x3;
	tie(x1, x2, x3) = solve3d(a, b, c);
	cout << x1 << " " << x2 << " " << x3 << endl;
}
0