Submission #995139

# Submission time Handle Problem Language Result Execution time Memory
995139 2024-06-08T13:47:25 Z mrwang Strange Device (APIO19_strange_device) C++14
100 / 100
403 ms 18976 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 3e18;
ll gcd(ll a, ll b){
    return __gcd(a, b);
}
ll get(ll a, ll b){
    ll c = (a / gcd(a, b + 1)), hi = inf / b;
    if(c > hi){
        c = inf;
    }
    else{
        c *= b;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    while(t--){
        ll n, a, b, i, l, r;
        cin >> n >> a >> b;
        ll x = get(a, b);
        vector<array<ll, 2>> v;
        bool ok = 1;
        for(i = 1; i <= n; i++){
            cin >> l >> r;
            ok &= ((r - l + 1) >= x);
            l %= x;
            r %= x;
            if(r < l){
                v.push_back({l, x - 1});
                v.push_back({0, r});
            }
            else{
                v.push_back({l, r});
            }
        }
        if(ok){
            cout << x << "\n";
            return 0;
        }
        sort(v.begin(), v.end());
        ll s = 0, hi = -1;
        for(i = 0; i < v.size(); i++){
            if(v[i][0] > hi){
                s += (v[i][1] - v[i][0] + 1);
                hi = v[i][1];
            }
            else
            {
                s+=max(0ll,v[i][1]-hi);
                hi=max(hi,v[i][1]);
            }
        }
        cout << s << "\n";
    }
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:49:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 6 ms 736 KB Output is correct
3 Correct 3 ms 736 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 348 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 0 ms 348 KB Output is correct
16 Correct 3 ms 732 KB Output is correct
17 Correct 31 ms 2492 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 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 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 1 ms 348 KB Output is correct
5 Correct 205 ms 17692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 295 ms 18184 KB Output is correct
3 Correct 282 ms 17288 KB Output is correct
4 Correct 272 ms 18876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 295 ms 18184 KB Output is correct
3 Correct 282 ms 17288 KB Output is correct
4 Correct 272 ms 18876 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 288 ms 18876 KB Output is correct
7 Correct 269 ms 17848 KB Output is correct
8 Correct 291 ms 18104 KB Output is correct
9 Correct 308 ms 18976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 295 ms 18184 KB Output is correct
3 Correct 282 ms 17288 KB Output is correct
4 Correct 272 ms 18876 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 29 ms 2520 KB Output is correct
7 Correct 29 ms 2520 KB Output is correct
8 Correct 26 ms 2568 KB Output is correct
9 Correct 30 ms 2520 KB Output is correct
10 Correct 27 ms 2516 KB Output is correct
11 Correct 44 ms 2492 KB Output is correct
12 Correct 27 ms 2516 KB Output is correct
13 Correct 30 ms 2520 KB Output is correct
14 Correct 26 ms 2520 KB Output is correct
15 Correct 31 ms 2516 KB Output is correct
16 Correct 30 ms 2516 KB Output is correct
17 Correct 28 ms 2520 KB Output is correct
18 Correct 327 ms 17608 KB Output is correct
19 Correct 281 ms 18580 KB Output is correct
20 Correct 317 ms 18612 KB Output is correct
21 Correct 30 ms 2516 KB Output is correct
22 Correct 26 ms 2520 KB Output is correct
23 Correct 89 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 30 ms 2616 KB Output is correct
3 Correct 41 ms 2520 KB Output is correct
4 Correct 403 ms 17076 KB Output is correct
5 Correct 30 ms 2516 KB Output is correct
6 Correct 31 ms 2520 KB Output is correct
7 Correct 31 ms 2516 KB Output is correct
8 Correct 43 ms 2520 KB Output is correct
9 Correct 30 ms 2564 KB Output is correct
10 Correct 30 ms 2520 KB Output is correct
11 Correct 31 ms 2520 KB Output is correct
12 Correct 27 ms 2516 KB Output is correct
13 Correct 30 ms 2520 KB Output is correct
14 Correct 302 ms 18100 KB Output is correct
15 Correct 31 ms 2520 KB Output is correct
16 Correct 272 ms 16932 KB Output is correct
17 Correct 270 ms 17844 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 6 ms 736 KB Output is correct
3 Correct 3 ms 736 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 348 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 0 ms 348 KB Output is correct
16 Correct 3 ms 732 KB Output is correct
17 Correct 31 ms 2492 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 205 ms 17692 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 295 ms 18184 KB Output is correct
31 Correct 282 ms 17288 KB Output is correct
32 Correct 272 ms 18876 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 288 ms 18876 KB Output is correct
35 Correct 269 ms 17848 KB Output is correct
36 Correct 291 ms 18104 KB Output is correct
37 Correct 308 ms 18976 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 29 ms 2520 KB Output is correct
40 Correct 29 ms 2520 KB Output is correct
41 Correct 26 ms 2568 KB Output is correct
42 Correct 30 ms 2520 KB Output is correct
43 Correct 27 ms 2516 KB Output is correct
44 Correct 44 ms 2492 KB Output is correct
45 Correct 27 ms 2516 KB Output is correct
46 Correct 30 ms 2520 KB Output is correct
47 Correct 26 ms 2520 KB Output is correct
48 Correct 31 ms 2516 KB Output is correct
49 Correct 30 ms 2516 KB Output is correct
50 Correct 28 ms 2520 KB Output is correct
51 Correct 327 ms 17608 KB Output is correct
52 Correct 281 ms 18580 KB Output is correct
53 Correct 317 ms 18612 KB Output is correct
54 Correct 30 ms 2516 KB Output is correct
55 Correct 26 ms 2520 KB Output is correct
56 Correct 89 ms 9040 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 30 ms 2616 KB Output is correct
59 Correct 41 ms 2520 KB Output is correct
60 Correct 403 ms 17076 KB Output is correct
61 Correct 30 ms 2516 KB Output is correct
62 Correct 31 ms 2520 KB Output is correct
63 Correct 31 ms 2516 KB Output is correct
64 Correct 43 ms 2520 KB Output is correct
65 Correct 30 ms 2564 KB Output is correct
66 Correct 30 ms 2520 KB Output is correct
67 Correct 31 ms 2520 KB Output is correct
68 Correct 27 ms 2516 KB Output is correct
69 Correct 30 ms 2520 KB Output is correct
70 Correct 302 ms 18100 KB Output is correct
71 Correct 31 ms 2520 KB Output is correct
72 Correct 272 ms 16932 KB Output is correct
73 Correct 270 ms 17844 KB Output is correct
74 Correct 1 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 736 KB Output is correct
80 Correct 376 ms 17616 KB Output is correct
81 Correct 323 ms 18364 KB Output is correct
82 Correct 308 ms 17732 KB Output is correct
83 Correct 304 ms 18876 KB Output is correct
84 Correct 307 ms 16824 KB Output is correct
85 Correct 319 ms 18356 KB Output is correct
86 Correct 88 ms 10176 KB Output is correct
87 Correct 0 ms 344 KB Output is correct