Submission #407023

# Submission time Handle Problem Language Result Execution time Memory
407023 2021-05-18T11:16:18 Z tengiz05 Strange Device (APIO19_strange_device) C++17
65 / 100
654 ms 40668 KB
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 2e18 + 100;
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n, A, B;
    std::cin >> n >> A >> B;
    i64 gcd = std::__gcd(A, B + 1);
    i64 cycle = A / gcd;
    if (inf / cycle < B) {
        cycle = inf;
    } else {
        cycle *= B;
    }
    std::vector<std::pair<i64, i64>> v;
    for (int i = 0; i < n; i++) {
        i64 l, r;
        std::cin >> l >> r;
        l %= cycle;
        r %= cycle;
        if (r - l + 1 >= cycle) {
            std::cout << cycle << "\n";
            return 0;
        }
        if (l <= r) {
            v.emplace_back(l, r);
        } else {
            v.emplace_back(0, r);
            v.emplace_back(l, cycle - 1);
        }
    }
    sort(v.begin(), v.end());
    std::vector<std::pair<i64, i64>> nw;
    nw.push_back(v[0]);
    for (int i = 1; i < int(v.size()); i++) {
        if (nw[nw.size() - 1].second >= v[i].first) {
            nw[nw.size() - 1].first = std::min(nw[nw.size() - 1].first, v[i].first);
            nw[nw.size() - 1].second = std::max(nw[nw.size() - 1].second, v[i].second);
        } else {
            nw.emplace_back(v[i]);
        }
    }
    i64 ans = 0;
    for (auto [l, r] : nw) {
        ans += r - l + 1;
    }
    std::cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 7 ms 848 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 53 ms 4932 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 367 ms 16860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 486 ms 40500 KB Output is correct
3 Correct 573 ms 40528 KB Output is correct
4 Correct 512 ms 40624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 486 ms 40500 KB Output is correct
3 Correct 573 ms 40528 KB Output is correct
4 Correct 512 ms 40624 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 487 ms 40552 KB Output is correct
7 Correct 506 ms 40464 KB Output is correct
8 Correct 654 ms 40504 KB Output is correct
9 Correct 534 ms 40544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 486 ms 40500 KB Output is correct
3 Correct 573 ms 40528 KB Output is correct
4 Correct 512 ms 40624 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 52 ms 4936 KB Output is correct
7 Correct 53 ms 4848 KB Output is correct
8 Correct 49 ms 4856 KB Output is correct
9 Correct 48 ms 4940 KB Output is correct
10 Correct 47 ms 4848 KB Output is correct
11 Correct 51 ms 4888 KB Output is correct
12 Correct 47 ms 4956 KB Output is correct
13 Correct 56 ms 4920 KB Output is correct
14 Correct 54 ms 4956 KB Output is correct
15 Correct 52 ms 4884 KB Output is correct
16 Correct 65 ms 4880 KB Output is correct
17 Correct 55 ms 4920 KB Output is correct
18 Correct 537 ms 40548 KB Output is correct
19 Correct 474 ms 40564 KB Output is correct
20 Correct 524 ms 40640 KB Output is correct
21 Correct 52 ms 4876 KB Output is correct
22 Correct 46 ms 4844 KB Output is correct
23 Correct 143 ms 8560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 50 ms 4856 KB Output is correct
3 Correct 51 ms 4868 KB Output is correct
4 Correct 628 ms 40564 KB Output is correct
5 Correct 50 ms 4956 KB Output is correct
6 Correct 51 ms 4948 KB Output is correct
7 Correct 59 ms 4932 KB Output is correct
8 Correct 62 ms 4960 KB Output is correct
9 Correct 50 ms 4948 KB Output is correct
10 Correct 51 ms 4860 KB Output is correct
11 Correct 50 ms 4940 KB Output is correct
12 Correct 59 ms 4924 KB Output is correct
13 Correct 72 ms 4920 KB Output is correct
14 Correct 550 ms 40548 KB Output is correct
15 Correct 54 ms 4840 KB Output is correct
16 Correct 528 ms 40668 KB Output is correct
17 Correct 479 ms 40500 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 7 ms 848 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 53 ms 4932 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Incorrect 1 ms 204 KB Output isn't correct
21 Halted 0 ms 0 KB -