結果

問題 No.550 夏休みの思い出(1)
ユーザー bal4ubal4u
提出日時 2019-07-16 14:21:22
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 30,436 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-20 12:34:40
合計ジャッジ時間 2,598 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 10 ms
4,384 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 11 ms
4,384 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 11 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 0 ms
4,380 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 7 ms
4,384 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,384 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 4 ms
4,384 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 8 ms
4,384 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 0 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 0 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 0 ms
4,380 KB
testcase_38 AC 0 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,384 KB
testcase_46 AC 1 ms
4,388 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 0 ms
4,384 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,384 KB
testcase_53 AC 1 ms
4,384 KB
testcase_54 AC 1 ms
4,384 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,380 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) >= 1000000) return 0;
	c = -C/a;
	if ((B-c) % a == 0 && -A-a == (B-c)/a) {
		solve(x+1, x+2, A+a, c), x[0] = a;
	} else if ((B+c) % a == 0 && A-a == (B+c)/a) {
		solve(x+1, x+2, A-a, -c), x[0] = -a;
	} else return 0;
	return 1;
}

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