結果

問題 No.550 夏休みの思い出(1)
ユーザー myantamyanta
提出日時 2017-07-28 23:47:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 43,904 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 13:10:42
合計ジャッジ時間 1,947 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using ll=long long;

using vll=vector<ll>;


int sign(ll x)
{
	if(x<0) return -1;
	return x>0;
}


int solve2(vll&ans, ll d, ll e)
{
	ll l, r, x;
	int l_sign, x_sign;

	l=-1000000000;
	r=d/2;

	x=l;
	l_sign=sign(x*x-d*x+e);
	if(l_sign==0)
	{
		if(e%l) return 0;
		ans[1]=l;
		ans[2]=e/l;
		return 1;
	}

	for(;l<=r;)
	{
		x=(l+r)/2;
		x_sign=sign(x*x-d*x+e);
		if(x_sign==0)
		{
			if(e%x) return 0;
			ans[1]=x;
			ans[2]=e/x;
			return 1;
		}
		if(x_sign==l_sign)
		{
			l=x+1;
		}
		else
		{
			r=x-1;
		}
	}
	return 0;
}


void solve3(vll&ans, ll a, ll b, ll c)
{
	if(c==0)
	{
		ans[0]=0;
		solve2(ans, -a, b);
		return;
	}

	for(ll i=1;i<=1000000;i++)
	{
		if(c%i) continue;
		if((b+c/i)%i) continue;

		ans[0]=i;
		if(solve2(ans, (b+c/i)/i,-c/i)) return;
	}

	for(ll i=1;i<=1000000;i++)
	{
		if(c%i) continue;
		if((b-c/i)%i) continue;

		ans[0]=-i;
		if(solve2(ans, -(b-c/i)/i, c/i)) return;
	}
}


int main(void)
{
	ll a, b, c;

	while(scanf("%lld%lld%lld", &a, &b, &c)==3)
	{
		vll ans(3);

		solve3(ans, a, b, c);
		sort(ans.begin(), ans.end());
		printf("%lld %lld %lld\n", ans[0], ans[1], ans[2]);
	}

	return 0;
}
0