結果

問題 No.186 中華風 (Easy)
ユーザー finefine
提出日時 2017-03-20 01:09:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 165,028 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-27 00:51:02
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1e18;

ll solve(ll x1, ll y1, ll x2, ll y2, ll limit) {
	for (ll i = x1; i <= limit; i += y1) {
		if (i == 0) continue;
		if (i % y2 == x2) return i;
	}
	return -1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x[3], y[3];
	for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];
	ll l1 = y[0] / __gcd(y[0], y[1]) * y[1];
	ll ans = solve(x[0], y[0], x[1], y[1], l1);
	if (ans == -1) {
		cout << -1 << endl;
		return 0;
	}
	ll l2 = l1 / __gcd(l1, y[2]) * y[2];
	ans = solve(ans % l1, l1, x[2], y[2], l2);
	cout << ans << endl;
	return 0;
}
0