結果

問題 No.186 中華風 (Easy)
ユーザー startcppstartcpp
提出日時 2016-11-08 14:59:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 894 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 52,056 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 15:03:57
合計ジャッジ時間 1,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//Easyの解法(条件式を1つずつ追加していく)を高速化. -> Hard, Mod取るのが面倒くさいなあ…
//((a % mod) % c == (b % mod) % c ⇔ a % c == b % cではないので)

#include <iostream>
#define int long long
using namespace std;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
	int x[3], y[3];
	int i, j;
	
	for (i = 0; i < 3; i++) cin >> x[i] >> y[i];
	
	int ans = 0;
	int t = 1;
	for (i = 0; i < 3; i++) {
		int diff = t % y[i];
		
		if (diff == 0) {
			if (ans % y[i] != x[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			int rem = (x[i] - ans + y[i]) % y[i];
			if (rem % diff != 0) {
				cout << -1 << endl;
				return 0;
			}
			ans += t * rem / diff;
		}
		t = lcm(t, y[i]);
	}
	if (ans == 0) { cout << t << endl; }
	else { cout << ans << endl; }
	return 0;
}
0