結果
| 問題 |
No.1486 ロボット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-30 19:20:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,775 bytes |
| コンパイル時間 | 1,014 ms |
| コンパイル使用メモリ | 97,276 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 16:03:03 |
| 合計ジャッジ時間 | 1,671 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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;
}