結果

問題 No.550 夏休みの思い出(1)
ユーザー bal4ubal4u
提出日時 2019-07-16 11:14:16
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 30,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 05:21:22
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: No.550 夏休みの思い出(1)
// 2019.7.16 bal4u

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

typedef long long ll;
#define ABS(x)  ((x)>=0?(x):-(x))

int x[3];
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

// X^2 + BX + C = 0    (A=1)
int solve(int *x1, int *x2, ll b, ll c) {
	ll d2, d;
	d2 = b*b - 4*c; if (d2 < 0) return 0;
	d = (ll)sqrt((double)d2) - 1;
	while (d*d != d2) d++;
	if ((-b + d) & 1) return 0;
	*x1 = (-b + d) / 2;
	*x2 = (-b - d) / 2;
	return 1;
}

ll A, B, C;
int check(ll a) {
	ll c;
	if (ABS(a) >= 1000000000) return 0;
	c = -C/a;
	if ((B-c) % a) return 0;
	if (-A-a != (B-c)/a) return 0;
	if (!solve(x+1, x+2, A+a, c)) return 0;
	x[0] = a;
	if ((ll)a*x[1]*x[2] == -C &&
		(ll)a + x[1] + x[2] == -A &&
		(ll)a*x[1] + (ll)x[1]*x[2] + (ll)x[2]*a == B) return 1;
	return 0;
}

int main()
{
	scanf("%lld%lld%lld", &A, &B, &C);
	if (C == 0) x[0] = 0, solve(x+1, x+2, A, B);
	else {
		ll c = C; if (c < 0) c = -c;
		int b = (int)sqrt((double)c);
		int a = 1; while (a <= b) {
			if (c % a == 0) {
				if (check(a)) break;
				if (check(-a)) break;
				if (check(c / a)) break;
				if (check(-c / a)) break;
			}
			a++;
		}
	}
	qsort(x, 3, sizeof(int), cmp);
	printf("%d %d %d\n", x[0], x[1], x[2]);
	return 0;
}
0