結果

問題 No.1486 ロボット
ユーザー TomorrowNextTomorrowNext
提出日時 2021-04-23 21:37:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 164,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 11:52:57
合計ジャッジ時間 2,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

void Main() {
    ll A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    ll period = (A + B) * (C + D) / __gcd(A + B, C + D);
    ll nPeriod = E / period;
    ll residual = E % period;

    ll ans = 0LL;
    for (ll i = 1; i <= period; ++i) {
        ll robot1 = i % (A + B);
        ll robot2 = i % (C + D);
        if (0 < robot1 && robot1 <= A && 0 < robot2 && robot2 <= C) {
            ++ans;
        }
    }
    ans *= nPeriod;
    for (ll i = 1; i <= residual; ++i) {
        ll robot1 = i % (A + B);
        ll robot2 = i % (C + D);
        if (0 < robot1 && robot1 <= A && 0 < robot2 && robot2 <= C) {
            ++ans;
        }
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}
0