Submission #147762

# Submission time Handle Problem Language Result Execution time Memory
147762 2019-08-30T15:23:00 Z kuroni Strange Device (APIO19_strange_device) C++17
100 / 100
1028 ms 19084 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 2E18;

vector<long long> ve;
int n;
long long a, b, l, r, cyc, ans = 0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> a >> b;
    a /= __gcd(a, b + 1);
    if (INF / a >= b)
        cyc = a * b;
    else
        cyc = INF;
    while (n--)
    {
        cin >> l >> r;
        if (r - l + 1 >= cyc)
        {
            ve.push_back(0);
            ve.push_back(-cyc);
        }
        else
        {
            l %= cyc; r %= cyc;
            ve.push_back(l);
            ve.push_back(-r - 1);
            if (l > r)
            {
                ve.push_back(0);
                ve.push_back(-cyc);
            }
        }
    }
    sort(ve.begin(), ve.end(), [](const long long &a, const long long &b) {
        return abs(a) < abs(b);
    });
    int cnt = 0;
    for (int i = 0; i < ve.size(); i++)
    {
        if (cnt > 0)
            ans += abs(ve[i]) - abs(ve[i - 1]);
        cnt += ve[i] / abs(ve[i]);
    }
    cout << ans;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:44:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ve.size(); i++)
                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 1 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 13 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1144 KB Output is correct
17 Correct 94 ms 4312 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 388 KB Output is correct
2 Correct 3 ms 396 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 444 KB Output is correct
5 Correct 499 ms 19084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 767 ms 18960 KB Output is correct
3 Correct 846 ms 18980 KB Output is correct
4 Correct 787 ms 18792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 767 ms 18960 KB Output is correct
3 Correct 846 ms 18980 KB Output is correct
4 Correct 787 ms 18792 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 826 ms 18228 KB Output is correct
7 Correct 778 ms 18132 KB Output is correct
8 Correct 810 ms 18516 KB Output is correct
9 Correct 951 ms 18332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 767 ms 18960 KB Output is correct
3 Correct 846 ms 18980 KB Output is correct
4 Correct 787 ms 18792 KB Output is correct
5 Correct 2 ms 424 KB Output is correct
6 Correct 75 ms 3736 KB Output is correct
7 Correct 81 ms 3696 KB Output is correct
8 Correct 73 ms 4076 KB Output is correct
9 Correct 79 ms 3952 KB Output is correct
10 Correct 71 ms 4204 KB Output is correct
11 Correct 80 ms 4156 KB Output is correct
12 Correct 77 ms 4220 KB Output is correct
13 Correct 91 ms 4080 KB Output is correct
14 Correct 72 ms 4208 KB Output is correct
15 Correct 93 ms 4204 KB Output is correct
16 Correct 90 ms 4044 KB Output is correct
17 Correct 78 ms 3820 KB Output is correct
18 Correct 805 ms 18196 KB Output is correct
19 Correct 763 ms 18192 KB Output is correct
20 Correct 975 ms 18228 KB Output is correct
21 Correct 94 ms 3976 KB Output is correct
22 Correct 71 ms 4044 KB Output is correct
23 Correct 206 ms 10692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 85 ms 3820 KB Output is correct
3 Correct 88 ms 3764 KB Output is correct
4 Correct 1006 ms 18236 KB Output is correct
5 Correct 90 ms 4208 KB Output is correct
6 Correct 90 ms 4052 KB Output is correct
7 Correct 91 ms 4076 KB Output is correct
8 Correct 87 ms 3796 KB Output is correct
9 Correct 86 ms 3820 KB Output is correct
10 Correct 93 ms 3816 KB Output is correct
11 Correct 89 ms 3868 KB Output is correct
12 Correct 91 ms 3792 KB Output is correct
13 Correct 94 ms 3808 KB Output is correct
14 Correct 963 ms 18272 KB Output is correct
15 Correct 97 ms 3740 KB Output is correct
16 Correct 736 ms 17748 KB Output is correct
17 Correct 784 ms 18040 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 1 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 13 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1144 KB Output is correct
17 Correct 94 ms 4312 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 252 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 388 KB Output is correct
25 Correct 3 ms 396 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 444 KB Output is correct
28 Correct 499 ms 19084 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 767 ms 18960 KB Output is correct
31 Correct 846 ms 18980 KB Output is correct
32 Correct 787 ms 18792 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 826 ms 18228 KB Output is correct
35 Correct 778 ms 18132 KB Output is correct
36 Correct 810 ms 18516 KB Output is correct
37 Correct 951 ms 18332 KB Output is correct
38 Correct 2 ms 424 KB Output is correct
39 Correct 75 ms 3736 KB Output is correct
40 Correct 81 ms 3696 KB Output is correct
41 Correct 73 ms 4076 KB Output is correct
42 Correct 79 ms 3952 KB Output is correct
43 Correct 71 ms 4204 KB Output is correct
44 Correct 80 ms 4156 KB Output is correct
45 Correct 77 ms 4220 KB Output is correct
46 Correct 91 ms 4080 KB Output is correct
47 Correct 72 ms 4208 KB Output is correct
48 Correct 93 ms 4204 KB Output is correct
49 Correct 90 ms 4044 KB Output is correct
50 Correct 78 ms 3820 KB Output is correct
51 Correct 805 ms 18196 KB Output is correct
52 Correct 763 ms 18192 KB Output is correct
53 Correct 975 ms 18228 KB Output is correct
54 Correct 94 ms 3976 KB Output is correct
55 Correct 71 ms 4044 KB Output is correct
56 Correct 206 ms 10692 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 85 ms 3820 KB Output is correct
59 Correct 88 ms 3764 KB Output is correct
60 Correct 1006 ms 18236 KB Output is correct
61 Correct 90 ms 4208 KB Output is correct
62 Correct 90 ms 4052 KB Output is correct
63 Correct 91 ms 4076 KB Output is correct
64 Correct 87 ms 3796 KB Output is correct
65 Correct 86 ms 3820 KB Output is correct
66 Correct 93 ms 3816 KB Output is correct
67 Correct 89 ms 3868 KB Output is correct
68 Correct 91 ms 3792 KB Output is correct
69 Correct 94 ms 3808 KB Output is correct
70 Correct 963 ms 18272 KB Output is correct
71 Correct 97 ms 3740 KB Output is correct
72 Correct 736 ms 17748 KB Output is correct
73 Correct 784 ms 18040 KB Output is correct
74 Correct 3 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 9 ms 1028 KB Output is correct
80 Correct 1028 ms 18284 KB Output is correct
81 Correct 1002 ms 18500 KB Output is correct
82 Correct 1002 ms 18516 KB Output is correct
83 Correct 954 ms 18364 KB Output is correct
84 Correct 946 ms 18348 KB Output is correct
85 Correct 959 ms 18384 KB Output is correct
86 Correct 209 ms 12588 KB Output is correct
87 Correct 2 ms 376 KB Output is correct