답안 #258398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258398 2020-08-05T21:29:13 Z DS007 이상한 기계 (APIO19_strange_device) C++14
100 / 100
799 ms 69192 KB
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long

int n, a, b;

bool overflow(int x, int y) {
    int result = x * y;
    if (result / x != y || result / y != x)
        return true;
    return false;
}

int sum() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    return ans;
}

int solveTestCase() {
    cin >> n >> a >> b;

    int temp = a / __gcd(a, b + 1);
    assert(a % __gcd(a, b + 1) == 0);
    if (overflow(temp, b))
        return cout << sum(), 0;

    temp *= b;
    //cerr << temp << "\n";
    vector<pair<int, int>> v;

    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;

        if (r - l + 1 >= temp)
            return cout << temp, 0;

        if (l % temp <= r % temp)
            v.emplace_back(l % temp, 1), v.emplace_back(r % temp + 1, 2);
        else
            v.emplace_back(l % temp, 1), v.emplace_back(temp, 2), v.emplace_back(0, 1), v.emplace_back(r % temp + 1, 2), assert(l % temp > r % temp + 1);
    }

    sort(v.begin(), v.end());

    int ans = 0, d = 0, last = 0;
    for (auto i : v) {
        if (d == 0)
            last = i.first;

        if (i.second == 1)
            d++;
        else
            d--;

        assert(d >= 0);
        if (d == 0)
            ans += i.first - last;
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--)
        solveTestCase();
}


Compilation message

strange_device.cpp: In function 'long long unsigned int solveTestCase()':
strange_device.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 71 ms 4596 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 444 ms 33376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 618 ms 33472 KB Output is correct
3 Correct 674 ms 33404 KB Output is correct
4 Correct 606 ms 33524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 618 ms 33472 KB Output is correct
3 Correct 674 ms 33404 KB Output is correct
4 Correct 606 ms 33524 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 626 ms 33284 KB Output is correct
7 Correct 617 ms 33344 KB Output is correct
8 Correct 637 ms 33528 KB Output is correct
9 Correct 717 ms 33340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 618 ms 33472 KB Output is correct
3 Correct 674 ms 33404 KB Output is correct
4 Correct 606 ms 33524 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 61 ms 4588 KB Output is correct
7 Correct 62 ms 4592 KB Output is correct
8 Correct 55 ms 4596 KB Output is correct
9 Correct 59 ms 4588 KB Output is correct
10 Correct 67 ms 4588 KB Output is correct
11 Correct 60 ms 4588 KB Output is correct
12 Correct 56 ms 4588 KB Output is correct
13 Correct 68 ms 4584 KB Output is correct
14 Correct 58 ms 4588 KB Output is correct
15 Correct 70 ms 4596 KB Output is correct
16 Correct 65 ms 4588 KB Output is correct
17 Correct 58 ms 4768 KB Output is correct
18 Correct 621 ms 33344 KB Output is correct
19 Correct 603 ms 33264 KB Output is correct
20 Correct 760 ms 33348 KB Output is correct
21 Correct 73 ms 4596 KB Output is correct
22 Correct 57 ms 4588 KB Output is correct
23 Correct 183 ms 16908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 66 ms 4588 KB Output is correct
3 Correct 66 ms 4584 KB Output is correct
4 Correct 793 ms 33396 KB Output is correct
5 Correct 65 ms 4588 KB Output is correct
6 Correct 67 ms 4596 KB Output is correct
7 Correct 66 ms 4716 KB Output is correct
8 Correct 70 ms 4640 KB Output is correct
9 Correct 67 ms 4616 KB Output is correct
10 Correct 73 ms 4588 KB Output is correct
11 Correct 70 ms 4584 KB Output is correct
12 Correct 63 ms 4632 KB Output is correct
13 Correct 72 ms 4584 KB Output is correct
14 Correct 784 ms 33344 KB Output is correct
15 Correct 71 ms 4588 KB Output is correct
16 Correct 616 ms 33344 KB Output is correct
17 Correct 630 ms 33516 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 71 ms 4596 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 444 ms 33376 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 618 ms 33472 KB Output is correct
31 Correct 674 ms 33404 KB Output is correct
32 Correct 606 ms 33524 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 626 ms 33284 KB Output is correct
35 Correct 617 ms 33344 KB Output is correct
36 Correct 637 ms 33528 KB Output is correct
37 Correct 717 ms 33340 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 61 ms 4588 KB Output is correct
40 Correct 62 ms 4592 KB Output is correct
41 Correct 55 ms 4596 KB Output is correct
42 Correct 59 ms 4588 KB Output is correct
43 Correct 67 ms 4588 KB Output is correct
44 Correct 60 ms 4588 KB Output is correct
45 Correct 56 ms 4588 KB Output is correct
46 Correct 68 ms 4584 KB Output is correct
47 Correct 58 ms 4588 KB Output is correct
48 Correct 70 ms 4596 KB Output is correct
49 Correct 65 ms 4588 KB Output is correct
50 Correct 58 ms 4768 KB Output is correct
51 Correct 621 ms 33344 KB Output is correct
52 Correct 603 ms 33264 KB Output is correct
53 Correct 760 ms 33348 KB Output is correct
54 Correct 73 ms 4596 KB Output is correct
55 Correct 57 ms 4588 KB Output is correct
56 Correct 183 ms 16908 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 66 ms 4588 KB Output is correct
59 Correct 66 ms 4584 KB Output is correct
60 Correct 793 ms 33396 KB Output is correct
61 Correct 65 ms 4588 KB Output is correct
62 Correct 67 ms 4596 KB Output is correct
63 Correct 66 ms 4716 KB Output is correct
64 Correct 70 ms 4640 KB Output is correct
65 Correct 67 ms 4616 KB Output is correct
66 Correct 73 ms 4588 KB Output is correct
67 Correct 70 ms 4584 KB Output is correct
68 Correct 63 ms 4632 KB Output is correct
69 Correct 72 ms 4584 KB Output is correct
70 Correct 784 ms 33344 KB Output is correct
71 Correct 71 ms 4588 KB Output is correct
72 Correct 616 ms 33344 KB Output is correct
73 Correct 630 ms 33516 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 6 ms 1408 KB Output is correct
80 Correct 798 ms 68980 KB Output is correct
81 Correct 799 ms 69020 KB Output is correct
82 Correct 732 ms 69020 KB Output is correct
83 Correct 731 ms 69016 KB Output is correct
84 Correct 744 ms 69132 KB Output is correct
85 Correct 793 ms 69192 KB Output is correct
86 Correct 176 ms 26860 KB Output is correct
87 Correct 1 ms 384 KB Output is correct