Submission #50407640


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    Num n, m, k;
    is >> n >> m >> k;

    const auto l = std::lcm(n, m);
    const auto unit = l / n + l /m - 2;
    const auto div = (k - 1) / unit;
    auto rem = (k - 1) % unit;

    Num mul_n = n;
    Num mul_m = m;
    Num ofs {0};
    while(rem-- >= 0) {
        ofs = std::min(mul_n, mul_m);
        if (mul_n < mul_m) {
            mul_n += n;
        } else {
            mul_m += m;
        }
    }

    os << (l * div + ofs) << "\n";
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task D - Only one of two
User zettsut
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1194 Byte
Status AC
Exec Time 40 ms
Memory 3676 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 35
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3568 KiB
example_01.txt AC 1 ms 3656 KiB
example_02.txt AC 1 ms 3464 KiB
hand_00.txt AC 1 ms 3552 KiB
hand_01.txt AC 1 ms 3528 KiB
hand_02.txt AC 1 ms 3488 KiB
hand_03.txt AC 1 ms 3528 KiB
hand_04.txt AC 1 ms 3568 KiB
hand_05.txt AC 1 ms 3460 KiB
hand_06.txt AC 1 ms 3452 KiB
random_00.txt AC 1 ms 3524 KiB
random_01.txt AC 1 ms 3652 KiB
random_02.txt AC 1 ms 3484 KiB
random_03.txt AC 1 ms 3420 KiB
random_04.txt AC 1 ms 3492 KiB
random_05.txt AC 1 ms 3448 KiB
random_06.txt AC 1 ms 3648 KiB
random_07.txt AC 29 ms 3528 KiB
random_08.txt AC 1 ms 3472 KiB
random_09.txt AC 1 ms 3648 KiB
random_10.txt AC 1 ms 3464 KiB
random_11.txt AC 1 ms 3468 KiB
random_12.txt AC 40 ms 3560 KiB
random_13.txt AC 17 ms 3448 KiB
random_14.txt AC 1 ms 3504 KiB
random_15.txt AC 1 ms 3504 KiB
random_16.txt AC 1 ms 3472 KiB
random_17.txt AC 28 ms 3564 KiB
random_18.txt AC 3 ms 3532 KiB
random_19.txt AC 1 ms 3564 KiB
random_20.txt AC 1 ms 3676 KiB
random_21.txt AC 2 ms 3524 KiB
random_22.txt AC 12 ms 3440 KiB
random_23.txt AC 1 ms 3532 KiB
random_24.txt AC 1 ms 3564 KiB