結果

問題 No.1486 ロボット
ユーザー Y_SY_S
提出日時 2021-04-30 19:20:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,775 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 97,024 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-25 20:15:59
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline, to_string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap, pair
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt,ceil,M_PI, pow, sin
#include <sstream>	//stringstream, getline
#include <numeric>	//gcd, accumlate
#include <deque>	//deque
#include <random>	//randam_device
#include <limits>	//numeric_limits

using namespace std;
constexpr long long int D_MOD = 1000000007;

inline long long int Greatest_Common_Divisor(long long int a, long long int b) {
	//aとbの最大公約数を返す
	while (a != 0 && b != 0) {
		if (a > b) {
			a = a - b;
		}
		else {
			b = b - a;
		}
	}
	return(a + b);
}

inline long long int Least_Common_Multiple(long long int gcd, long long int a, long long int b) {
	//aとbの最小公倍数を返す
	//先に最大公約数gcdが計算済である必要がある
	return (a * b) / gcd;
}

int main() {

	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;

	int x = a + b;
	int y = c + d;
	long long int LCM = Least_Common_Multiple(Greatest_Common_Divisor(x, y), x, y);

	vector<bool> rob_a(x);
	vector<bool> rob_b(y);


	for (int i = 0; i < a; i++) {
		rob_a[i] = true;
	}
	for (int i = 0; i < c; i++) {
		rob_b[i] = true;
	}

	int ans = 0;

	if (e <= LCM) {
		for (int i = 0; i < e; i++) {
			if (rob_a[i % x] && rob_b[i % y]) {
				ans++;
			}
		}
	}
	else {
		int temp = 0;
		for (int i = 0; i < LCM; i++) {
			if (rob_a[i % x] && rob_b[i % y]) {
				temp++;
			}
		}

		ans = temp * (e / LCM);

		for (int i = 0; i < e % LCM; i++) {
			if (rob_a[i % x] && rob_b[i % y]) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;

}
0