답안 #407036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407036 2021-05-18T11:41:34 Z tengiz05 이상한 기계 (APIO19_strange_device) C++17
65 / 100
566 ms 40640 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 (cycle > 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 868 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 6 ms 776 KB Output is correct
17 Correct 60 ms 4952 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 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 351 ms 16832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 497 ms 40560 KB Output is correct
3 Correct 530 ms 40552 KB Output is correct
4 Correct 476 ms 40580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 497 ms 40560 KB Output is correct
3 Correct 530 ms 40552 KB Output is correct
4 Correct 476 ms 40580 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 499 ms 40484 KB Output is correct
7 Correct 490 ms 40620 KB Output is correct
8 Correct 474 ms 40576 KB Output is correct
9 Correct 547 ms 40640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 497 ms 40560 KB Output is correct
3 Correct 530 ms 40552 KB Output is correct
4 Correct 476 ms 40580 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 48 ms 4836 KB Output is correct
7 Correct 51 ms 4884 KB Output is correct
8 Correct 47 ms 4952 KB Output is correct
9 Correct 47 ms 4920 KB Output is correct
10 Correct 47 ms 4916 KB Output is correct
11 Correct 50 ms 4932 KB Output is correct
12 Correct 48 ms 4900 KB Output is correct
13 Correct 51 ms 4904 KB Output is correct
14 Correct 47 ms 4892 KB Output is correct
15 Correct 53 ms 4948 KB Output is correct
16 Correct 52 ms 4852 KB Output is correct
17 Correct 48 ms 4924 KB Output is correct
18 Correct 495 ms 40612 KB Output is correct
19 Correct 476 ms 40640 KB Output is correct
20 Correct 526 ms 40468 KB Output is correct
21 Correct 51 ms 4924 KB Output is correct
22 Correct 46 ms 4920 KB Output is correct
23 Correct 149 ms 8692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 51 ms 4904 KB Output is correct
3 Correct 62 ms 4868 KB Output is correct
4 Correct 566 ms 40612 KB Output is correct
5 Correct 56 ms 4920 KB Output is correct
6 Correct 53 ms 4880 KB Output is correct
7 Correct 51 ms 4848 KB Output is correct
8 Correct 52 ms 4920 KB Output is correct
9 Correct 50 ms 4920 KB Output is correct
10 Correct 50 ms 4860 KB Output is correct
11 Correct 51 ms 4920 KB Output is correct
12 Correct 45 ms 4920 KB Output is correct
13 Correct 52 ms 4908 KB Output is correct
14 Correct 538 ms 40592 KB Output is correct
15 Correct 50 ms 4920 KB Output is correct
16 Correct 514 ms 40628 KB Output is correct
17 Correct 478 ms 40616 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 868 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 6 ms 776 KB Output is correct
17 Correct 60 ms 4952 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 -