Submission #1034561

# Submission time Handle Problem Language Result Execution time Memory
1034561 2024-07-25T14:52:15 Z andrei_iorgulescu Strange Device (APIO19_strange_device) C++14
100 / 100
932 ms 69868 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n,A,B;
int l[1000005],r[1000005];

signed main()
{
    cin >> n >> A >> B;
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i];
    __int128 AA = A, BB = B;
    __int128 FF = AA * BB / __gcd(AA,BB + 1);
    if (FF > r[n])
    {
        int sumlen = 0;
        for (int i = 1; i <= n; i++)
            sumlen += r[i] - l[i] + 1;
        cout << sumlen;
    }
    else
    {
        int F = FF;
        for (int i = 1; i <= n; i++)
        {
            if (r[i] - l[i] + 1 >= F)
            {
                cout << F;
                return 0;
            }
        }
        vector<pair<int,int>> h;
        for (int i = 1; i <= n; i++)
        {
            if (r[i] % F >= l[i] % F)
                h.push_back({l[i] % F,r[i] % F});
            else
                h.push_back({0,r[i] % F}),h.push_back({l[i] % F,F - 1});
        }
        sort(h.begin(),h.end());
        int ans = F;
        int rmax = -1;
        if (h.back().second != F - 1)
            ans -= F - 1 - h.back().second;
        for (auto it : h)
        {
            if (it.first > rmax + 1)
                ans -= (it.first - rmax - 1);
            rmax = max(rmax,it.second);
        }
        cout << ans;
    }
    return 0;
}

///cate resturi modulo A * B / gcd(A,B + 1) gasesc?
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 9 ms 1368 KB Output is correct
3 Correct 12 ms 1204 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 9 ms 1224 KB Output is correct
17 Correct 94 ms 7020 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 630 ms 51648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 875 ms 60812 KB Output is correct
3 Correct 902 ms 60884 KB Output is correct
4 Correct 885 ms 60600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 875 ms 60812 KB Output is correct
3 Correct 902 ms 60884 KB Output is correct
4 Correct 885 ms 60600 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 861 ms 60640 KB Output is correct
7 Correct 887 ms 60600 KB Output is correct
8 Correct 848 ms 60600 KB Output is correct
9 Correct 882 ms 60640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 875 ms 60812 KB Output is correct
3 Correct 902 ms 60884 KB Output is correct
4 Correct 885 ms 60600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 106 ms 7020 KB Output is correct
7 Correct 88 ms 7080 KB Output is correct
8 Correct 86 ms 7108 KB Output is correct
9 Correct 95 ms 7060 KB Output is correct
10 Correct 92 ms 7244 KB Output is correct
11 Correct 86 ms 7084 KB Output is correct
12 Correct 89 ms 7108 KB Output is correct
13 Correct 89 ms 7108 KB Output is correct
14 Correct 93 ms 7212 KB Output is correct
15 Correct 89 ms 7112 KB Output is correct
16 Correct 88 ms 7032 KB Output is correct
17 Correct 83 ms 7108 KB Output is correct
18 Correct 893 ms 60616 KB Output is correct
19 Correct 885 ms 60644 KB Output is correct
20 Correct 884 ms 60780 KB Output is correct
21 Correct 88 ms 7108 KB Output is correct
22 Correct 87 ms 7108 KB Output is correct
23 Correct 289 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 87 ms 7108 KB Output is correct
3 Correct 89 ms 7112 KB Output is correct
4 Correct 879 ms 60720 KB Output is correct
5 Correct 88 ms 7084 KB Output is correct
6 Correct 89 ms 7036 KB Output is correct
7 Correct 90 ms 7180 KB Output is correct
8 Correct 92 ms 7112 KB Output is correct
9 Correct 88 ms 7216 KB Output is correct
10 Correct 83 ms 7364 KB Output is correct
11 Correct 88 ms 7112 KB Output is correct
12 Correct 86 ms 7116 KB Output is correct
13 Correct 89 ms 7112 KB Output is correct
14 Correct 867 ms 60732 KB Output is correct
15 Correct 84 ms 7120 KB Output is correct
16 Correct 848 ms 60600 KB Output is correct
17 Correct 855 ms 60620 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 9 ms 1368 KB Output is correct
3 Correct 12 ms 1204 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 9 ms 1224 KB Output is correct
17 Correct 94 ms 7020 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 448 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 630 ms 51648 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 875 ms 60812 KB Output is correct
31 Correct 902 ms 60884 KB Output is correct
32 Correct 885 ms 60600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 861 ms 60640 KB Output is correct
35 Correct 887 ms 60600 KB Output is correct
36 Correct 848 ms 60600 KB Output is correct
37 Correct 882 ms 60640 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 106 ms 7020 KB Output is correct
40 Correct 88 ms 7080 KB Output is correct
41 Correct 86 ms 7108 KB Output is correct
42 Correct 95 ms 7060 KB Output is correct
43 Correct 92 ms 7244 KB Output is correct
44 Correct 86 ms 7084 KB Output is correct
45 Correct 89 ms 7108 KB Output is correct
46 Correct 89 ms 7108 KB Output is correct
47 Correct 93 ms 7212 KB Output is correct
48 Correct 89 ms 7112 KB Output is correct
49 Correct 88 ms 7032 KB Output is correct
50 Correct 83 ms 7108 KB Output is correct
51 Correct 893 ms 60616 KB Output is correct
52 Correct 885 ms 60644 KB Output is correct
53 Correct 884 ms 60780 KB Output is correct
54 Correct 88 ms 7108 KB Output is correct
55 Correct 87 ms 7108 KB Output is correct
56 Correct 289 ms 23996 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 87 ms 7108 KB Output is correct
59 Correct 89 ms 7112 KB Output is correct
60 Correct 879 ms 60720 KB Output is correct
61 Correct 88 ms 7084 KB Output is correct
62 Correct 89 ms 7036 KB Output is correct
63 Correct 90 ms 7180 KB Output is correct
64 Correct 92 ms 7112 KB Output is correct
65 Correct 88 ms 7216 KB Output is correct
66 Correct 83 ms 7364 KB Output is correct
67 Correct 88 ms 7112 KB Output is correct
68 Correct 86 ms 7116 KB Output is correct
69 Correct 89 ms 7112 KB Output is correct
70 Correct 867 ms 60732 KB Output is correct
71 Correct 84 ms 7120 KB Output is correct
72 Correct 848 ms 60600 KB Output is correct
73 Correct 855 ms 60620 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 448 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 9 ms 1372 KB Output is correct
80 Correct 896 ms 69592 KB Output is correct
81 Correct 882 ms 69544 KB Output is correct
82 Correct 932 ms 69868 KB Output is correct
83 Correct 870 ms 69644 KB Output is correct
84 Correct 824 ms 69672 KB Output is correct
85 Correct 905 ms 69676 KB Output is correct
86 Correct 279 ms 26552 KB Output is correct
87 Correct 0 ms 348 KB Output is correct