結果

問題 No.186 中華風 (Easy)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-19 23:40:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 144,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:42:56
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 7 ms
4,384 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

long long gcd(long long a, long long b){
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {
	long long X1, Y1, X2, Y2, X3, Y3;
	cin >> Y1 >> X1 >> Y2 >> X2 >> Y3 >> X3;
	long long ans = Y3;
	if (Y3 == 0) ans = X3;
	int count = X2 + 1000;

	long long add = X3;

	while (count > 0 && ans >= 0){
		if (ans % X2 == Y2) break;
		ans += add;
		count--;
	}
	if (count <= 0 || ans < 0){
		cout << -1 << endl;
		return 0;
	}

	add = (X3 * X2) / gcd(X3, X2);

	count = X1 + 1000;
	while (count > 0){
		if (ans % X1 == Y1) break;
		ans += add;
		count--;
	}

	if (count <= 0 || ans < 0){
		cout << -1 << endl;
		return 0;
	}

	cout << ans << endl;
}
0