結果

問題 No.186 中華風 (Easy)
ユーザー bal4ubal4u
提出日時 2019-05-02 18:51:44
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 29,296 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 04:50:55
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 0 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 0 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 0 ms
4,380 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No. 186 中華風 (Easy)
// 2019.5.2 bal4u

#include <stdio.h>

long long extended_gcd(long long a, long long b, long long *x, long long *y)
{
	long long d;
	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a % b, y, x);
	*y -= a / b * (*x);
	return d;
}

int chinese(long long *a1, long long *a2, int *a, int *m, int sz)
{
	int i;
    long long p, q, d, t, r, M;
	
	r = 0, M = 1;
    for (i = 0; i < sz; i++) {
		d = extended_gcd(M, m[i], &p, &q);
        if ((a[i] - r) % d) return 0;
        t = (a[i] - r)/d * p % (m[i]/d);
        r += M * t;
        M *= m[i]/d;
    }
    *a1 = r % M, *a2 = M;
	return 1;
}

int x[3], y[3];

int main()
{
	int i, f;
	long long a1, a2;
	
	f = 0; for (i = 0; i < 3; i++) {
		scanf("%d%d", x+i, y+i);
		if (x[i]) f = 1;
	}
	if (chinese(&a1, &a2, x, y, 3)) printf("%lld\n", f? a1: a2);
	else puts("-1");
	return 0;
}
0