Submission #50379685
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;
if (n > m) {
std::swap(n, m);
}
bool mul = (m % n) == 0;
const auto l = std::lcm(n, m);
const auto size = l / n + l / m - 2;
Num div = (k - 1) / size;
Num rem = (k - 1) % size;
PQ<Num> q;
q.push(n);
q.push(m);
Num ofs = 0;
while(rem-- >= 0) {
const auto cur = q.top();
q.pop();
ofs = cur;
if ((cur % n) == 0) {
Num nc = cur + n;
if (nc < l) {
q.push(nc);
}
} else if (!mul) {
Num mc = cur + m;
if (mc < l) {
q.push(mc);
}
}
}
Num ans = l * div + ofs;
os << ans << "\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 | 1499 Byte |
| Status | AC |
| Exec Time | 402 ms |
| Memory | 3620 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| 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 | 3532 KiB |
| example_01.txt | AC | 1 ms | 3620 KiB |
| example_02.txt | AC | 1 ms | 3496 KiB |
| hand_00.txt | AC | 1 ms | 3572 KiB |
| hand_01.txt | AC | 1 ms | 3572 KiB |
| hand_02.txt | AC | 1 ms | 3444 KiB |
| hand_03.txt | AC | 1 ms | 3464 KiB |
| hand_04.txt | AC | 1 ms | 3372 KiB |
| hand_05.txt | AC | 1 ms | 3472 KiB |
| hand_06.txt | AC | 1 ms | 3500 KiB |
| random_00.txt | AC | 1 ms | 3568 KiB |
| random_01.txt | AC | 1 ms | 3444 KiB |
| random_02.txt | AC | 1 ms | 3532 KiB |
| random_03.txt | AC | 1 ms | 3364 KiB |
| random_04.txt | AC | 1 ms | 3488 KiB |
| random_05.txt | AC | 1 ms | 3568 KiB |
| random_06.txt | AC | 1 ms | 3464 KiB |
| random_07.txt | AC | 379 ms | 3488 KiB |
| random_08.txt | AC | 1 ms | 3572 KiB |
| random_09.txt | AC | 2 ms | 3464 KiB |
| random_10.txt | AC | 1 ms | 3568 KiB |
| random_11.txt | AC | 1 ms | 3368 KiB |
| random_12.txt | AC | 402 ms | 3568 KiB |
| random_13.txt | AC | 143 ms | 3500 KiB |
| random_14.txt | AC | 2 ms | 3568 KiB |
| random_15.txt | AC | 1 ms | 3464 KiB |
| random_16.txt | AC | 1 ms | 3464 KiB |
| random_17.txt | AC | 285 ms | 3456 KiB |
| random_18.txt | AC | 31 ms | 3460 KiB |
| random_19.txt | AC | 1 ms | 3448 KiB |
| random_20.txt | AC | 1 ms | 3460 KiB |
| random_21.txt | AC | 1 ms | 3464 KiB |
| random_22.txt | AC | 140 ms | 3420 KiB |
| random_23.txt | AC | 4 ms | 3456 KiB |
| random_24.txt | AC | 1 ms | 3532 KiB |