Submission #1100594

# Submission time Handle Problem Language Result Execution time Memory
1100594 2024-10-14T09:42:15 Z vjudge1 Strange Device (APIO19_strange_device) C++17
35 / 100
921 ms 34612 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 = A * B / __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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 10 ms 2944 KB Output is correct
3 Correct 10 ms 2896 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2552 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 10 ms 2896 KB Output is correct
17 Correct 101 ms 9916 KB Output is correct
18 Incorrect 1 ms 2384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Incorrect 1 ms 2384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 2 ms 2384 KB Output is correct
5 Correct 650 ms 34480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 903 ms 34488 KB Output is correct
3 Correct 880 ms 34480 KB Output is correct
4 Correct 876 ms 34516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 903 ms 34488 KB Output is correct
3 Correct 880 ms 34480 KB Output is correct
4 Correct 876 ms 34516 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 857 ms 34524 KB Output is correct
7 Correct 844 ms 34480 KB Output is correct
8 Correct 846 ms 34512 KB Output is correct
9 Correct 920 ms 34480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 903 ms 34488 KB Output is correct
3 Correct 880 ms 34480 KB Output is correct
4 Correct 876 ms 34516 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 90 ms 9948 KB Output is correct
7 Correct 90 ms 9952 KB Output is correct
8 Correct 88 ms 9956 KB Output is correct
9 Correct 96 ms 9916 KB Output is correct
10 Correct 90 ms 9916 KB Output is correct
11 Correct 102 ms 9916 KB Output is correct
12 Correct 90 ms 9916 KB Output is correct
13 Correct 92 ms 9948 KB Output is correct
14 Correct 87 ms 9916 KB Output is correct
15 Correct 98 ms 9916 KB Output is correct
16 Correct 98 ms 9916 KB Output is correct
17 Correct 93 ms 9940 KB Output is correct
18 Correct 921 ms 34480 KB Output is correct
19 Correct 921 ms 34480 KB Output is correct
20 Correct 920 ms 34480 KB Output is correct
21 Correct 92 ms 9956 KB Output is correct
22 Correct 84 ms 9924 KB Output is correct
23 Correct 287 ms 21204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 94 ms 9916 KB Output is correct
3 Correct 91 ms 9944 KB Output is correct
4 Correct 904 ms 34612 KB Output is correct
5 Correct 88 ms 9916 KB Output is correct
6 Correct 90 ms 9916 KB Output is correct
7 Correct 88 ms 9916 KB Output is correct
8 Correct 107 ms 9916 KB Output is correct
9 Correct 91 ms 9916 KB Output is correct
10 Correct 89 ms 9916 KB Output is correct
11 Correct 88 ms 9916 KB Output is correct
12 Correct 86 ms 9924 KB Output is correct
13 Correct 93 ms 9852 KB Output is correct
14 Correct 919 ms 34492 KB Output is correct
15 Correct 104 ms 9920 KB Output is correct
16 Correct 880 ms 34516 KB Output is correct
17 Correct 888 ms 34552 KB Output is correct
18 Incorrect 1 ms 2384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 10 ms 2944 KB Output is correct
3 Correct 10 ms 2896 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2552 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 10 ms 2896 KB Output is correct
17 Correct 101 ms 9916 KB Output is correct
18 Incorrect 1 ms 2384 KB Output isn't correct
19 Halted 0 ms 0 KB -