Submission #1016320

# Submission time Handle Problem Language Result Execution time Memory
1016320 2024-07-07T18:43:02 Z VMaksimoski008 Strange Device (APIO19_strange_device) C++17
100 / 100
325 ms 53960 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);
    
    ll n, A, B;
    cin >> n >> A >> B;

    ll P = min( (__int128_t)A / (__int128_t)__gcd(A, B + 1) * (__int128_t)B, (__int128_t)1e18 + 1 );

    vector<pair<ll, ll> > st;
    for(int i=0; i<n; i++) {
        ll L, R;
        cin >> L >> R;

        if(R - L + 1 >= P) {
            cout << P << '\n';
            return 0;
        }
        
        ll a = L % P, b = R % P;
        if(L == R) {
            st.push_back({ a, b });
        } else if(a < b) {
            st.push_back({ a, b });
        } else {
            st.push_back({ a, P - 1 });
            st.push_back({ 0, b });
        }
    }

    ll res = 0;
    sort(st.begin(), st.end());
    ll left_end=st[0].first, right_end=st[0].second;
    for(int i=1; i<st.size(); i++) {
        if(st[i].first > right_end) {
            res += right_end - left_end + 1;
            left_end = st[i].first;
            right_end = st[i].second;
        } else {
            right_end = max(right_end, st[i].second);
        }
    }

    cout << res + right_end - left_end + 1 << '\n';
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=1; i<st.size(); i++) {
      |                  ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 452 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 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 31 ms 5648 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 416 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 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 192 ms 41376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 265 ms 53280 KB Output is correct
3 Correct 253 ms 53936 KB Output is correct
4 Correct 266 ms 53680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 265 ms 53280 KB Output is correct
3 Correct 253 ms 53936 KB Output is correct
4 Correct 266 ms 53680 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 296 ms 53420 KB Output is correct
7 Correct 265 ms 53288 KB Output is correct
8 Correct 249 ms 53612 KB Output is correct
9 Correct 277 ms 53432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 265 ms 53280 KB Output is correct
3 Correct 253 ms 53936 KB Output is correct
4 Correct 266 ms 53680 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 32 ms 5632 KB Output is correct
7 Correct 37 ms 5836 KB Output is correct
8 Correct 36 ms 5728 KB Output is correct
9 Correct 27 ms 5832 KB Output is correct
10 Correct 25 ms 5836 KB Output is correct
11 Correct 28 ms 5796 KB Output is correct
12 Correct 25 ms 5800 KB Output is correct
13 Correct 28 ms 5832 KB Output is correct
14 Correct 25 ms 5844 KB Output is correct
15 Correct 31 ms 5836 KB Output is correct
16 Correct 29 ms 5844 KB Output is correct
17 Correct 37 ms 5832 KB Output is correct
18 Correct 262 ms 53916 KB Output is correct
19 Correct 251 ms 53936 KB Output is correct
20 Correct 279 ms 53232 KB Output is correct
21 Correct 29 ms 5832 KB Output is correct
22 Correct 25 ms 5836 KB Output is correct
23 Correct 77 ms 20556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 28 ms 5836 KB Output is correct
3 Correct 30 ms 5760 KB Output is correct
4 Correct 278 ms 53932 KB Output is correct
5 Correct 40 ms 5836 KB Output is correct
6 Correct 30 ms 5704 KB Output is correct
7 Correct 28 ms 5840 KB Output is correct
8 Correct 30 ms 5788 KB Output is correct
9 Correct 31 ms 5832 KB Output is correct
10 Correct 29 ms 5836 KB Output is correct
11 Correct 30 ms 5832 KB Output is correct
12 Correct 27 ms 5708 KB Output is correct
13 Correct 30 ms 5736 KB Output is correct
14 Correct 292 ms 53604 KB Output is correct
15 Correct 27 ms 5676 KB Output is correct
16 Correct 250 ms 53296 KB Output is correct
17 Correct 261 ms 53544 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 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 452 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 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 31 ms 5648 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 416 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 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 192 ms 41376 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 265 ms 53280 KB Output is correct
31 Correct 253 ms 53936 KB Output is correct
32 Correct 266 ms 53680 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 296 ms 53420 KB Output is correct
35 Correct 265 ms 53288 KB Output is correct
36 Correct 249 ms 53612 KB Output is correct
37 Correct 277 ms 53432 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 32 ms 5632 KB Output is correct
40 Correct 37 ms 5836 KB Output is correct
41 Correct 36 ms 5728 KB Output is correct
42 Correct 27 ms 5832 KB Output is correct
43 Correct 25 ms 5836 KB Output is correct
44 Correct 28 ms 5796 KB Output is correct
45 Correct 25 ms 5800 KB Output is correct
46 Correct 28 ms 5832 KB Output is correct
47 Correct 25 ms 5844 KB Output is correct
48 Correct 31 ms 5836 KB Output is correct
49 Correct 29 ms 5844 KB Output is correct
50 Correct 37 ms 5832 KB Output is correct
51 Correct 262 ms 53916 KB Output is correct
52 Correct 251 ms 53936 KB Output is correct
53 Correct 279 ms 53232 KB Output is correct
54 Correct 29 ms 5832 KB Output is correct
55 Correct 25 ms 5836 KB Output is correct
56 Correct 77 ms 20556 KB Output is correct
57 Correct 0 ms 456 KB Output is correct
58 Correct 28 ms 5836 KB Output is correct
59 Correct 30 ms 5760 KB Output is correct
60 Correct 278 ms 53932 KB Output is correct
61 Correct 40 ms 5836 KB Output is correct
62 Correct 30 ms 5704 KB Output is correct
63 Correct 28 ms 5840 KB Output is correct
64 Correct 30 ms 5788 KB Output is correct
65 Correct 31 ms 5832 KB Output is correct
66 Correct 29 ms 5836 KB Output is correct
67 Correct 30 ms 5832 KB Output is correct
68 Correct 27 ms 5708 KB Output is correct
69 Correct 30 ms 5736 KB Output is correct
70 Correct 292 ms 53604 KB Output is correct
71 Correct 27 ms 5676 KB Output is correct
72 Correct 250 ms 53296 KB Output is correct
73 Correct 261 ms 53544 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 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 1116 KB Output is correct
80 Correct 291 ms 53876 KB Output is correct
81 Correct 325 ms 53960 KB Output is correct
82 Correct 274 ms 53472 KB Output is correct
83 Correct 285 ms 53932 KB Output is correct
84 Correct 310 ms 53496 KB Output is correct
85 Correct 275 ms 53428 KB Output is correct
86 Correct 82 ms 19900 KB Output is correct
87 Correct 0 ms 348 KB Output is correct