結果
問題 |
No.1486 ロボット
|
ユーザー |
![]() |
提出日時 | 2023-09-10 01:31:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,328 bytes |
コンパイル時間 | 1,863 ms |
コンパイル使用メモリ | 192,920 KB |
最終ジャッジ日時 | 2025-02-16 20:54:47 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> #include<iostream> #include<map> #include<vector> #include <algorithm> #include<math.h> #include <iomanip> #include<set> #include <numeric> #include<string> using ll = long long; using namespace std; int main() { ll a, b, c, d, e, lcm, cnt1 = 0, cnt2 = 0, coin = 0, ans, r; cin >> a >> b >> c >> d >> e; bool x = true, y = true; lcm = (a+b)*(c+d)/gcd(a+b, c+d); for (int i = 0; i < lcm; i++){ cnt1++; cnt2++; if (x && y) coin++; if (x && cnt1 == a){ x = false; cnt1 = 0; } else if (!x && cnt1 == b){ x = true; cnt1 = 0; } if (y && cnt2 == c){ y = false; cnt2 = 0; } else if (!y && cnt2 == d){ y = true; cnt2 = 0; } } coin *= e/lcm; r = e%lcm; for (int i = 0; i < r; i++){ cnt1++; cnt2++; if (x && y) coin++; if (x && cnt1 == a){ x = false; cnt1 = 0; } else if (!x && cnt1 == b){ x = true; cnt1 = 0; } if (y && cnt2 == c){ y = false; cnt2 = 0; } else if (!y && cnt2 == d){ y = true; cnt2 = 0; } } cout << coin << endl; }