Submission #1067612

# Submission time Handle Problem Language Result Execution time Memory
1067612 2024-08-20T21:30:46 Z DeathIsAwe Strange Device (APIO19_strange_device) C++17
100 / 100
1043 ms 71752 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ll n, a, b; cin >> n >> a >> b;
    vector<pair<ll,ll>> turnedon(n);
    __int128_t divisor = (__int128_t)gcd(a, b + 1);
    __int128_t multiple = ((__int128_t)a * (__int128_t)(b + 1)) / divisor;
    __int128_t num = multiple - (__int128_t)(multiple / (__int128_t)(b + 1));
    for (int i=0;i<n;i++) {
        cin >> turnedon[i].first >> turnedon[i].second;
    }
    ll limit;
    if (num > 1000000000000000000) {
        limit = 1000000000000000001;
    } else {
        limit = num;
    }


    vector<pair<ll,ll>> ansarr;
    for (int i=0;i<n;i++) {
        if (turnedon[i].second - turnedon[i].first + 1 >= limit) {
            cout << limit;
            return 0;
        }
        turnedon[i].first %= limit; turnedon[i].second %= limit;
        if (turnedon[i].first > turnedon[i].second) {
            ansarr.push_back(make_pair(turnedon[i].first, limit - 1));
            ansarr.push_back(make_pair(0, turnedon[i].second));
        } else {
            ansarr.push_back(make_pair(turnedon[i].first, turnedon[i].second));
        }
    }
    sort(ansarr.begin(), ansarr.end());
    ll ans = 0, tracker = -1;
    for (pair<ll,ll> j: ansarr) {
        if (tracker < j.first) {
            ans += j.second - j.first + 1;
            tracker = j.second;
        } else if (tracker < j.second) {
            ans += j.second - tracker;
            tracker = j.second;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 860 KB Output is correct
3 Correct 9 ms 860 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 1 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 1 ms 348 KB Output is correct
16 Correct 9 ms 860 KB Output is correct
17 Correct 95 ms 4164 KB Output is correct
18 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 0 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 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 688 ms 33844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 896 ms 33840 KB Output is correct
3 Correct 1014 ms 32696 KB Output is correct
4 Correct 993 ms 32568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 896 ms 33840 KB Output is correct
3 Correct 1014 ms 32696 KB Output is correct
4 Correct 993 ms 32568 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 940 ms 32508 KB Output is correct
7 Correct 960 ms 32440 KB Output is correct
8 Correct 914 ms 32564 KB Output is correct
9 Correct 936 ms 32440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 896 ms 33840 KB Output is correct
3 Correct 1014 ms 32696 KB Output is correct
4 Correct 993 ms 32568 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 94 ms 4168 KB Output is correct
7 Correct 97 ms 4168 KB Output is correct
8 Correct 89 ms 4164 KB Output is correct
9 Correct 107 ms 4040 KB Output is correct
10 Correct 91 ms 4036 KB Output is correct
11 Correct 94 ms 4292 KB Output is correct
12 Correct 120 ms 4036 KB Output is correct
13 Correct 92 ms 5180 KB Output is correct
14 Correct 90 ms 4036 KB Output is correct
15 Correct 135 ms 4164 KB Output is correct
16 Correct 95 ms 4040 KB Output is correct
17 Correct 95 ms 4164 KB Output is correct
18 Correct 945 ms 33468 KB Output is correct
19 Correct 928 ms 32568 KB Output is correct
20 Correct 946 ms 33096 KB Output is correct
21 Correct 93 ms 4040 KB Output is correct
22 Correct 97 ms 4036 KB Output is correct
23 Correct 307 ms 14064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 98 ms 4168 KB Output is correct
3 Correct 94 ms 4040 KB Output is correct
4 Correct 965 ms 34116 KB Output is correct
5 Correct 95 ms 4036 KB Output is correct
6 Correct 95 ms 4148 KB Output is correct
7 Correct 99 ms 4296 KB Output is correct
8 Correct 101 ms 4172 KB Output is correct
9 Correct 106 ms 4144 KB Output is correct
10 Correct 95 ms 4040 KB Output is correct
11 Correct 106 ms 4148 KB Output is correct
12 Correct 94 ms 4036 KB Output is correct
13 Correct 95 ms 4164 KB Output is correct
14 Correct 967 ms 32564 KB Output is correct
15 Correct 93 ms 4160 KB Output is correct
16 Correct 945 ms 32564 KB Output is correct
17 Correct 916 ms 32448 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 860 KB Output is correct
3 Correct 9 ms 860 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 1 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 1 ms 348 KB Output is correct
16 Correct 9 ms 860 KB Output is correct
17 Correct 95 ms 4164 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 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 596 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 688 ms 33844 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 896 ms 33840 KB Output is correct
31 Correct 1014 ms 32696 KB Output is correct
32 Correct 993 ms 32568 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 940 ms 32508 KB Output is correct
35 Correct 960 ms 32440 KB Output is correct
36 Correct 914 ms 32564 KB Output is correct
37 Correct 936 ms 32440 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 94 ms 4168 KB Output is correct
40 Correct 97 ms 4168 KB Output is correct
41 Correct 89 ms 4164 KB Output is correct
42 Correct 107 ms 4040 KB Output is correct
43 Correct 91 ms 4036 KB Output is correct
44 Correct 94 ms 4292 KB Output is correct
45 Correct 120 ms 4036 KB Output is correct
46 Correct 92 ms 5180 KB Output is correct
47 Correct 90 ms 4036 KB Output is correct
48 Correct 135 ms 4164 KB Output is correct
49 Correct 95 ms 4040 KB Output is correct
50 Correct 95 ms 4164 KB Output is correct
51 Correct 945 ms 33468 KB Output is correct
52 Correct 928 ms 32568 KB Output is correct
53 Correct 946 ms 33096 KB Output is correct
54 Correct 93 ms 4040 KB Output is correct
55 Correct 97 ms 4036 KB Output is correct
56 Correct 307 ms 14064 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 98 ms 4168 KB Output is correct
59 Correct 94 ms 4040 KB Output is correct
60 Correct 965 ms 34116 KB Output is correct
61 Correct 95 ms 4036 KB Output is correct
62 Correct 95 ms 4148 KB Output is correct
63 Correct 99 ms 4296 KB Output is correct
64 Correct 101 ms 4172 KB Output is correct
65 Correct 106 ms 4144 KB Output is correct
66 Correct 95 ms 4040 KB Output is correct
67 Correct 106 ms 4148 KB Output is correct
68 Correct 94 ms 4036 KB Output is correct
69 Correct 95 ms 4164 KB Output is correct
70 Correct 967 ms 32564 KB Output is correct
71 Correct 93 ms 4160 KB Output is correct
72 Correct 945 ms 32564 KB Output is correct
73 Correct 916 ms 32448 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 14 ms 1224 KB Output is correct
80 Correct 1043 ms 71344 KB Output is correct
81 Correct 982 ms 70832 KB Output is correct
82 Correct 994 ms 70588 KB Output is correct
83 Correct 975 ms 71608 KB Output is correct
84 Correct 981 ms 71752 KB Output is correct
85 Correct 1014 ms 69820 KB Output is correct
86 Correct 330 ms 26568 KB Output is correct
87 Correct 0 ms 344 KB Output is correct