Submission #646055

# Submission time Handle Problem Language Result Execution time Memory
646055 2022-09-28T14:28:30 Z Tenis0206 Strange Device (APIO19_strange_device) C++11
100 / 100
747 ms 100276 KB
#include <bits/stdc++.h>
#define int __int128

using namespace std;

int n,a,b;

vector<pair<int,int>> eves;

int gcd(int a, int b)
{
    int r = a % b;
    while(r)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long N,A,B;
    cin>>N>>A>>B;
    n = N;
    a = A;
    b = B;
    int div = a * b / gcd(b + 1, a);
    bool done = false;
    for(int i=1; i<=n; i++)
    {
        int l,r;
        long long L,R;
        cin>>L>>R;
        l = L;
        r = R;
        if(r - l + 1 >= div)
        {
            done = true;
        }
        l %= div;
        r %= div;
        if(l <= r)
        {
            eves.push_back({l,1});
            eves.push_back({r+1,-1});
        }
        else
        {
            eves.push_back({0,1});
            eves.push_back({r+1,-1});
            eves.push_back({l,1});
            eves.push_back({div,-1});
        }
    }
    if(done)
    {
        vector<short> r;
        while(div)
        {
            r.push_back(div % 10);
            div /= 10;
        }
        reverse(r.begin(),r.end());
        for(auto it : r)
        {
            cout<<it;
        }
        cout<<'\n';
        return 0;
    }
    sort(eves.begin(),eves.end());
    int nr = 0;
    int rez = 0;
    int last = 0;
    for(auto it : eves)
    {
        if(nr==0 && it.second==1)
        {
            last = it.first;
        }
        nr += it.second;
        if(nr==0 && it.second==-1)
        {
            rez += it.first - last;
        }
    }
    vector<short> r;
    while(rez)
    {
        r.push_back(rez % 10);
        rez /= 10;
    }
    reverse(r.begin(),r.end());
    for(auto it : r)
    {
        cout<<it;
    }
    cout<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1772 KB Output is correct
3 Correct 9 ms 1748 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 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 66 ms 11320 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 0 ms 212 KB Output is correct
4 Correct 0 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 1 ms 456 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 387 ms 66064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 67312 KB Output is correct
3 Correct 625 ms 66236 KB Output is correct
4 Correct 587 ms 69076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 67312 KB Output is correct
3 Correct 625 ms 66236 KB Output is correct
4 Correct 587 ms 69076 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 553 ms 69112 KB Output is correct
7 Correct 568 ms 69052 KB Output is correct
8 Correct 593 ms 69240 KB Output is correct
9 Correct 736 ms 69176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 67312 KB Output is correct
3 Correct 625 ms 66236 KB Output is correct
4 Correct 587 ms 69076 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 58 ms 11216 KB Output is correct
7 Correct 66 ms 11232 KB Output is correct
8 Correct 74 ms 11316 KB Output is correct
9 Correct 53 ms 11320 KB Output is correct
10 Correct 52 ms 11324 KB Output is correct
11 Correct 54 ms 11288 KB Output is correct
12 Correct 52 ms 11308 KB Output is correct
13 Correct 59 ms 11308 KB Output is correct
14 Correct 69 ms 11276 KB Output is correct
15 Correct 70 ms 11308 KB Output is correct
16 Correct 59 ms 11232 KB Output is correct
17 Correct 52 ms 11268 KB Output is correct
18 Correct 587 ms 69116 KB Output is correct
19 Correct 555 ms 69044 KB Output is correct
20 Correct 747 ms 69060 KB Output is correct
21 Correct 65 ms 11328 KB Output is correct
22 Correct 47 ms 11280 KB Output is correct
23 Correct 165 ms 43052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 64 ms 11316 KB Output is correct
3 Correct 60 ms 9660 KB Output is correct
4 Correct 718 ms 66124 KB Output is correct
5 Correct 58 ms 9664 KB Output is correct
6 Correct 62 ms 9664 KB Output is correct
7 Correct 56 ms 9668 KB Output is correct
8 Correct 62 ms 9664 KB Output is correct
9 Correct 55 ms 9672 KB Output is correct
10 Correct 64 ms 9576 KB Output is correct
11 Correct 60 ms 9628 KB Output is correct
12 Correct 50 ms 9660 KB Output is correct
13 Correct 63 ms 9608 KB Output is correct
14 Correct 670 ms 66224 KB Output is correct
15 Correct 63 ms 9660 KB Output is correct
16 Correct 518 ms 69012 KB Output is correct
17 Correct 544 ms 69040 KB Output is correct
18 Correct 1 ms 220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1772 KB Output is correct
3 Correct 9 ms 1748 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 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 66 ms 11320 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 0 ms 212 KB Output is correct
22 Correct 0 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 1 ms 456 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 2 ms 488 KB Output is correct
28 Correct 387 ms 66064 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 647 ms 67312 KB Output is correct
31 Correct 625 ms 66236 KB Output is correct
32 Correct 587 ms 69076 KB Output is correct
33 Correct 0 ms 316 KB Output is correct
34 Correct 553 ms 69112 KB Output is correct
35 Correct 568 ms 69052 KB Output is correct
36 Correct 593 ms 69240 KB Output is correct
37 Correct 736 ms 69176 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 58 ms 11216 KB Output is correct
40 Correct 66 ms 11232 KB Output is correct
41 Correct 74 ms 11316 KB Output is correct
42 Correct 53 ms 11320 KB Output is correct
43 Correct 52 ms 11324 KB Output is correct
44 Correct 54 ms 11288 KB Output is correct
45 Correct 52 ms 11308 KB Output is correct
46 Correct 59 ms 11308 KB Output is correct
47 Correct 69 ms 11276 KB Output is correct
48 Correct 70 ms 11308 KB Output is correct
49 Correct 59 ms 11232 KB Output is correct
50 Correct 52 ms 11268 KB Output is correct
51 Correct 587 ms 69116 KB Output is correct
52 Correct 555 ms 69044 KB Output is correct
53 Correct 747 ms 69060 KB Output is correct
54 Correct 65 ms 11328 KB Output is correct
55 Correct 47 ms 11280 KB Output is correct
56 Correct 165 ms 43052 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 64 ms 11316 KB Output is correct
59 Correct 60 ms 9660 KB Output is correct
60 Correct 718 ms 66124 KB Output is correct
61 Correct 58 ms 9664 KB Output is correct
62 Correct 62 ms 9664 KB Output is correct
63 Correct 56 ms 9668 KB Output is correct
64 Correct 62 ms 9664 KB Output is correct
65 Correct 55 ms 9672 KB Output is correct
66 Correct 64 ms 9576 KB Output is correct
67 Correct 60 ms 9628 KB Output is correct
68 Correct 50 ms 9660 KB Output is correct
69 Correct 63 ms 9608 KB Output is correct
70 Correct 670 ms 66224 KB Output is correct
71 Correct 63 ms 9660 KB Output is correct
72 Correct 518 ms 69012 KB Output is correct
73 Correct 544 ms 69040 KB Output is correct
74 Correct 1 ms 220 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 6 ms 1772 KB Output is correct
80 Correct 721 ms 100168 KB Output is correct
81 Correct 730 ms 100200 KB Output is correct
82 Correct 692 ms 100276 KB Output is correct
83 Correct 684 ms 100140 KB Output is correct
84 Correct 689 ms 100188 KB Output is correct
85 Correct 672 ms 100140 KB Output is correct
86 Correct 163 ms 43140 KB Output is correct
87 Correct 1 ms 212 KB Output is correct