結果

問題 No.186 中華風 (Easy)
ユーザー m1025o1184tm1025o1184t
提出日時 2020-02-23 14:30:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 166,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 00:58:54
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
4,376 KB
testcase_01 AC 25 ms
4,376 KB
testcase_02 AC 59 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 54 ms
4,380 KB
testcase_05 AC 64 ms
4,376 KB
testcase_06 AC 139 ms
4,376 KB
testcase_07 AC 49 ms
4,376 KB
testcase_08 AC 64 ms
4,376 KB
testcase_09 AC 61 ms
4,380 KB
testcase_10 AC 180 ms
4,376 KB
testcase_11 AC 86 ms
4,380 KB
testcase_12 AC 16 ms
4,380 KB
testcase_13 AC 90 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 31 ms
4,376 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<ll> x(3), y(3);
	rep(i, 3) cin >> x[i] >> y[i];
	ll ans;
	ll pin = y[1] + 1;
	bool elf = false;
	rep(i, pin) {
		ll res = x[0] + y[0] * i;
		if (res % y[1] == x[1]) {
			elf = true;
			ans = res;
			break;
		}
	}
	if (!elf) { puts("-1"); return 0; }
	elf = false;
	pin = y[2] + 1;
	rep(i, pin) {
		ll res = ans + lcm(y[0], y[1]) * i;
		if (res % y[2] == x[2]) {
			elf = true;
			ans = res;
			break;
		}
	}
	if (!elf) { puts("-1"); return 0; }
	dunk(ans != 0 ? ans : lcm(y[0], lcm(y[1], y[2])));
	return 0;
}
0