Submission #363856

# Submission time Handle Problem Language Result Execution time Memory
363856 2021-02-07T11:38:51 Z Mahdi_Shokoufi Strange Device (APIO19_strange_device) C++17
100 / 100
732 ms 81004 KB
//In the name of Allah
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair

typedef long long ll;

const ll inf = 1e18 + 10;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll p = (inf / b < a / __gcd(a, b + 1) ? inf : a / __gcd(a, b + 1) * b);
    set < pair < ll , ll > > st;
    for (int i = 0; i < n; i ++){
        ll l, r;
        cin >> l >> r;
        if (p <= r - l + 1)
            return cout << p, 0;
        l %= p; r %= p;
        if (l <= r)
            st.insert(mp(l, -r));
        else
            st.insert(mp(l, -p + 1)), st.insert(mp(0, -r));
    }
    ll ans = 0, mx = -1;
    for (auto itr = st.begin(); itr != st.end(); itr ++){
        ll x = itr -> first, y = -(itr -> second);
        ans += max(0LL, y - max(mx + 1, x) + 1);
        mx = max(mx, y);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1004 KB Output is correct
3 Correct 6 ms 1004 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1388 KB Output is correct
17 Correct 66 ms 10348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 295 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 698 ms 62956 KB Output is correct
3 Correct 664 ms 62956 KB Output is correct
4 Correct 688 ms 73820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 698 ms 62956 KB Output is correct
3 Correct 664 ms 62956 KB Output is correct
4 Correct 688 ms 73820 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 732 ms 73576 KB Output is correct
7 Correct 673 ms 73708 KB Output is correct
8 Correct 669 ms 73516 KB Output is correct
9 Correct 701 ms 73708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 698 ms 62956 KB Output is correct
3 Correct 664 ms 62956 KB Output is correct
4 Correct 688 ms 73820 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 65 ms 10348 KB Output is correct
7 Correct 63 ms 10348 KB Output is correct
8 Correct 64 ms 10348 KB Output is correct
9 Correct 67 ms 10348 KB Output is correct
10 Correct 62 ms 10348 KB Output is correct
11 Correct 62 ms 10348 KB Output is correct
12 Correct 64 ms 10348 KB Output is correct
13 Correct 66 ms 10348 KB Output is correct
14 Correct 63 ms 10348 KB Output is correct
15 Correct 68 ms 10348 KB Output is correct
16 Correct 67 ms 10348 KB Output is correct
17 Correct 66 ms 10348 KB Output is correct
18 Correct 661 ms 74604 KB Output is correct
19 Correct 673 ms 76652 KB Output is correct
20 Correct 698 ms 75500 KB Output is correct
21 Correct 64 ms 10348 KB Output is correct
22 Correct 69 ms 10304 KB Output is correct
23 Correct 165 ms 12908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 66 ms 6636 KB Output is correct
3 Correct 65 ms 6636 KB Output is correct
4 Correct 689 ms 62956 KB Output is correct
5 Correct 64 ms 6636 KB Output is correct
6 Correct 67 ms 6636 KB Output is correct
7 Correct 66 ms 6636 KB Output is correct
8 Correct 66 ms 6636 KB Output is correct
9 Correct 64 ms 6636 KB Output is correct
10 Correct 65 ms 6636 KB Output is correct
11 Correct 65 ms 6636 KB Output is correct
12 Correct 64 ms 6636 KB Output is correct
13 Correct 67 ms 10420 KB Output is correct
14 Correct 700 ms 81004 KB Output is correct
15 Correct 68 ms 10348 KB Output is correct
16 Correct 674 ms 74348 KB Output is correct
17 Correct 659 ms 74476 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1004 KB Output is correct
3 Correct 6 ms 1004 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1388 KB Output is correct
17 Correct 66 ms 10348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 295 ms 5740 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 698 ms 62956 KB Output is correct
31 Correct 664 ms 62956 KB Output is correct
32 Correct 688 ms 73820 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 732 ms 73576 KB Output is correct
35 Correct 673 ms 73708 KB Output is correct
36 Correct 669 ms 73516 KB Output is correct
37 Correct 701 ms 73708 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 65 ms 10348 KB Output is correct
40 Correct 63 ms 10348 KB Output is correct
41 Correct 64 ms 10348 KB Output is correct
42 Correct 67 ms 10348 KB Output is correct
43 Correct 62 ms 10348 KB Output is correct
44 Correct 62 ms 10348 KB Output is correct
45 Correct 64 ms 10348 KB Output is correct
46 Correct 66 ms 10348 KB Output is correct
47 Correct 63 ms 10348 KB Output is correct
48 Correct 68 ms 10348 KB Output is correct
49 Correct 67 ms 10348 KB Output is correct
50 Correct 66 ms 10348 KB Output is correct
51 Correct 661 ms 74604 KB Output is correct
52 Correct 673 ms 76652 KB Output is correct
53 Correct 698 ms 75500 KB Output is correct
54 Correct 64 ms 10348 KB Output is correct
55 Correct 69 ms 10304 KB Output is correct
56 Correct 165 ms 12908 KB Output is correct
57 Correct 0 ms 364 KB Output is correct
58 Correct 66 ms 6636 KB Output is correct
59 Correct 65 ms 6636 KB Output is correct
60 Correct 689 ms 62956 KB Output is correct
61 Correct 64 ms 6636 KB Output is correct
62 Correct 67 ms 6636 KB Output is correct
63 Correct 66 ms 6636 KB Output is correct
64 Correct 66 ms 6636 KB Output is correct
65 Correct 64 ms 6636 KB Output is correct
66 Correct 65 ms 6636 KB Output is correct
67 Correct 65 ms 6636 KB Output is correct
68 Correct 64 ms 6636 KB Output is correct
69 Correct 67 ms 10420 KB Output is correct
70 Correct 700 ms 81004 KB Output is correct
71 Correct 68 ms 10348 KB Output is correct
72 Correct 674 ms 74348 KB Output is correct
73 Correct 659 ms 74476 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 7 ms 1388 KB Output is correct
80 Correct 695 ms 78268 KB Output is correct
81 Correct 690 ms 78060 KB Output is correct
82 Correct 708 ms 78188 KB Output is correct
83 Correct 683 ms 73708 KB Output is correct
84 Correct 720 ms 75884 KB Output is correct
85 Correct 677 ms 75884 KB Output is correct
86 Correct 133 ms 13036 KB Output is correct
87 Correct 1 ms 364 KB Output is correct