답안 #407066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407066 2021-05-18T12:29:34 Z tengiz05 이상한 기계 (APIO19_strange_device) C++17
65 / 100
601 ms 40800 KB
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1e18 + 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 (A / gcd > inf / 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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 848 KB Output is correct
3 Correct 6 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 204 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 52 ms 4880 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 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 382 ms 16764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 493 ms 40560 KB Output is correct
3 Correct 511 ms 40600 KB Output is correct
4 Correct 513 ms 40612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 493 ms 40560 KB Output is correct
3 Correct 511 ms 40600 KB Output is correct
4 Correct 513 ms 40612 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 513 ms 40588 KB Output is correct
7 Correct 514 ms 40684 KB Output is correct
8 Correct 551 ms 40800 KB Output is correct
9 Correct 601 ms 40508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 493 ms 40560 KB Output is correct
3 Correct 511 ms 40600 KB Output is correct
4 Correct 513 ms 40612 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 49 ms 4828 KB Output is correct
7 Correct 62 ms 4876 KB Output is correct
8 Correct 49 ms 5048 KB Output is correct
9 Correct 48 ms 4948 KB Output is correct
10 Correct 61 ms 4920 KB Output is correct
11 Correct 51 ms 4976 KB Output is correct
12 Correct 50 ms 4908 KB Output is correct
13 Correct 50 ms 4920 KB Output is correct
14 Correct 51 ms 4860 KB Output is correct
15 Correct 52 ms 4848 KB Output is correct
16 Correct 51 ms 4936 KB Output is correct
17 Correct 48 ms 4852 KB Output is correct
18 Correct 498 ms 40600 KB Output is correct
19 Correct 502 ms 40572 KB Output is correct
20 Correct 538 ms 40596 KB Output is correct
21 Correct 51 ms 4920 KB Output is correct
22 Correct 48 ms 4932 KB Output is correct
23 Correct 147 ms 8748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 63 ms 4920 KB Output is correct
3 Correct 60 ms 4940 KB Output is correct
4 Correct 566 ms 40540 KB Output is correct
5 Correct 65 ms 4840 KB Output is correct
6 Correct 51 ms 4948 KB Output is correct
7 Correct 51 ms 4852 KB Output is correct
8 Correct 52 ms 4920 KB Output is correct
9 Correct 53 ms 4948 KB Output is correct
10 Correct 54 ms 4924 KB Output is correct
11 Correct 53 ms 4948 KB Output is correct
12 Correct 47 ms 4832 KB Output is correct
13 Correct 53 ms 4884 KB Output is correct
14 Correct 573 ms 40672 KB Output is correct
15 Correct 51 ms 4920 KB Output is correct
16 Correct 485 ms 40544 KB Output is correct
17 Correct 476 ms 40648 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 848 KB Output is correct
3 Correct 6 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 204 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 52 ms 4880 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 -