Submission #568944

# Submission time Handle Problem Language Result Execution time Memory
568944 2022-05-26T11:18:46 Z four_specks Strange Device (APIO19_strange_device) C++17
100 / 100
517 ms 40456 KB
#include <bits/stdc++.h>

using namespace std;

inline namespace
{
} // namespace

void solve()
{
    int n;
    long a, b;
    cin >> n >> a >> b;

    vector<array<long, 2>> v(n);
    for (auto &[x, y] : v)
        cin >> x >> y, ++y;

    if (LONG_MAX / a / b)
    {
        long c = a * b / gcd(a, b + 1);

        vector<array<long, 2>> u;
        for (auto [x, y] : v)
        {
            if (y - x >= c)
                u.push_back({0, c});
            else
            {
                x %= c, y %= c;
                if (x < y)
                    u.push_back({x, y});
                else
                    u.push_back({x, c}), u.push_back({0, y});
            }
        }
        sort(u.begin(), u.end());

        long cnt = 0;

        long d = 0;
        for (auto [x, y] : u)
        {
            if (y > d)
            {
                cnt += y - max(x, d);
                d = y;
            }
        }

        cout << cnt << '\n';
    }
    else
    {
        long cnt = 0;
        for (auto [x, y] : v)
            cnt += y - x;

        cout << cnt << '\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 50 ms 7748 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 334 ms 34148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 463 ms 40456 KB Output is correct
3 Correct 445 ms 34452 KB Output is correct
4 Correct 438 ms 39236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 463 ms 40456 KB Output is correct
3 Correct 445 ms 34452 KB Output is correct
4 Correct 438 ms 39236 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 452 ms 39184 KB Output is correct
7 Correct 458 ms 39140 KB Output is correct
8 Correct 457 ms 39172 KB Output is correct
9 Correct 517 ms 39104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 463 ms 40456 KB Output is correct
3 Correct 445 ms 34452 KB Output is correct
4 Correct 438 ms 39236 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 48 ms 7760 KB Output is correct
7 Correct 57 ms 7756 KB Output is correct
8 Correct 47 ms 7752 KB Output is correct
9 Correct 46 ms 7748 KB Output is correct
10 Correct 44 ms 7612 KB Output is correct
11 Correct 45 ms 7540 KB Output is correct
12 Correct 47 ms 7588 KB Output is correct
13 Correct 49 ms 7656 KB Output is correct
14 Correct 43 ms 7600 KB Output is correct
15 Correct 52 ms 7624 KB Output is correct
16 Correct 53 ms 7600 KB Output is correct
17 Correct 46 ms 7628 KB Output is correct
18 Correct 465 ms 38384 KB Output is correct
19 Correct 458 ms 38744 KB Output is correct
20 Correct 483 ms 38036 KB Output is correct
21 Correct 48 ms 7632 KB Output is correct
22 Correct 43 ms 7636 KB Output is correct
23 Correct 146 ms 17432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 48 ms 7212 KB Output is correct
3 Correct 51 ms 7200 KB Output is correct
4 Correct 492 ms 34492 KB Output is correct
5 Correct 47 ms 7192 KB Output is correct
6 Correct 49 ms 7268 KB Output is correct
7 Correct 48 ms 7232 KB Output is correct
8 Correct 48 ms 7240 KB Output is correct
9 Correct 48 ms 7240 KB Output is correct
10 Correct 49 ms 7228 KB Output is correct
11 Correct 48 ms 7160 KB Output is correct
12 Correct 45 ms 7240 KB Output is correct
13 Correct 50 ms 7208 KB Output is correct
14 Correct 473 ms 34504 KB Output is correct
15 Correct 48 ms 7200 KB Output is correct
16 Correct 451 ms 36440 KB Output is correct
17 Correct 441 ms 39344 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 50 ms 7748 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 334 ms 34148 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 463 ms 40456 KB Output is correct
31 Correct 445 ms 34452 KB Output is correct
32 Correct 438 ms 39236 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 452 ms 39184 KB Output is correct
35 Correct 458 ms 39140 KB Output is correct
36 Correct 457 ms 39172 KB Output is correct
37 Correct 517 ms 39104 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 48 ms 7760 KB Output is correct
40 Correct 57 ms 7756 KB Output is correct
41 Correct 47 ms 7752 KB Output is correct
42 Correct 46 ms 7748 KB Output is correct
43 Correct 44 ms 7612 KB Output is correct
44 Correct 45 ms 7540 KB Output is correct
45 Correct 47 ms 7588 KB Output is correct
46 Correct 49 ms 7656 KB Output is correct
47 Correct 43 ms 7600 KB Output is correct
48 Correct 52 ms 7624 KB Output is correct
49 Correct 53 ms 7600 KB Output is correct
50 Correct 46 ms 7628 KB Output is correct
51 Correct 465 ms 38384 KB Output is correct
52 Correct 458 ms 38744 KB Output is correct
53 Correct 483 ms 38036 KB Output is correct
54 Correct 48 ms 7632 KB Output is correct
55 Correct 43 ms 7636 KB Output is correct
56 Correct 146 ms 17432 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 48 ms 7212 KB Output is correct
59 Correct 51 ms 7200 KB Output is correct
60 Correct 492 ms 34492 KB Output is correct
61 Correct 47 ms 7192 KB Output is correct
62 Correct 49 ms 7268 KB Output is correct
63 Correct 48 ms 7232 KB Output is correct
64 Correct 48 ms 7240 KB Output is correct
65 Correct 48 ms 7240 KB Output is correct
66 Correct 49 ms 7228 KB Output is correct
67 Correct 48 ms 7160 KB Output is correct
68 Correct 45 ms 7240 KB Output is correct
69 Correct 50 ms 7208 KB Output is correct
70 Correct 473 ms 34504 KB Output is correct
71 Correct 48 ms 7200 KB Output is correct
72 Correct 451 ms 36440 KB Output is correct
73 Correct 441 ms 39344 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 276 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 6 ms 1248 KB Output is correct
80 Correct 487 ms 33468 KB Output is correct
81 Correct 479 ms 33584 KB Output is correct
82 Correct 458 ms 33596 KB Output is correct
83 Correct 472 ms 33488 KB Output is correct
84 Correct 451 ms 33600 KB Output is correct
85 Correct 458 ms 33492 KB Output is correct
86 Correct 156 ms 18324 KB Output is correct
87 Correct 0 ms 212 KB Output is correct