Submission #392246

# Submission time Handle Problem Language Result Execution time Memory
392246 2021-04-20T17:30:44 Z BartolM Strange Device (APIO19_strange_device) C++17
100 / 100
605 ms 53508 KB
#define DEBUG 1
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const ll MAX=1e18+2;

int n, fl=0;
ll A, B, gc;
vector <pll> v;

int main() {
    scanf("%d %lld %lld", &n, &A, &B);
    gc=__gcd(A, B+1);
    ll block=A/gc*B;
    if (A/gc>MAX/B) block=MAX;

    for (int i=0; i<n; ++i) {
        ll l, r;
        scanf("%lld %lld", &l, &r);
        if (r-l+1>block) fl=1;
        l%=block; r%=block;

        if (l<=r) v.pb(mp(l, r));
        else v.pb(mp(l, block-1)), v.pb(mp(0, r));
    }
    if (fl) {
        printf("%lld\n", block);
        return 0;
    }
    sort(v.begin(), v.end());
    ll lef=-1, rig=-2, sol=0;
    for (pll pp:v) {
        if (rig<pp.X) sol+=rig-lef+1, rig=pp.Y, lef=pp.X;
        else rig=max(rig, pp.Y);
    }
    sol+=rig-lef+1;
    printf("%lld\n", sol);
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %lld %lld", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%lld %lld", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 8 ms 972 KB Output is correct
3 Correct 6 ms 972 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 976 KB Output is correct
17 Correct 57 ms 5608 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 406 ms 41220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 538 ms 34664 KB Output is correct
3 Correct 518 ms 34604 KB Output is correct
4 Correct 512 ms 53244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 538 ms 34664 KB Output is correct
3 Correct 518 ms 34604 KB Output is correct
4 Correct 512 ms 53244 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 530 ms 53208 KB Output is correct
7 Correct 569 ms 53296 KB Output is correct
8 Correct 540 ms 53224 KB Output is correct
9 Correct 565 ms 53280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 538 ms 34664 KB Output is correct
3 Correct 518 ms 34604 KB Output is correct
4 Correct 512 ms 53244 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 51 ms 5680 KB Output is correct
7 Correct 66 ms 5712 KB Output is correct
8 Correct 64 ms 5680 KB Output is correct
9 Correct 67 ms 5684 KB Output is correct
10 Correct 50 ms 5596 KB Output is correct
11 Correct 54 ms 5584 KB Output is correct
12 Correct 52 ms 5680 KB Output is correct
13 Correct 55 ms 5632 KB Output is correct
14 Correct 52 ms 5684 KB Output is correct
15 Correct 55 ms 5684 KB Output is correct
16 Correct 55 ms 5740 KB Output is correct
17 Correct 52 ms 5600 KB Output is correct
18 Correct 535 ms 53232 KB Output is correct
19 Correct 563 ms 53308 KB Output is correct
20 Correct 573 ms 53256 KB Output is correct
21 Correct 56 ms 5680 KB Output is correct
22 Correct 49 ms 5676 KB Output is correct
23 Correct 166 ms 18472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 64 ms 5588 KB Output is correct
3 Correct 54 ms 5632 KB Output is correct
4 Correct 598 ms 53256 KB Output is correct
5 Correct 53 ms 5680 KB Output is correct
6 Correct 54 ms 5680 KB Output is correct
7 Correct 53 ms 5704 KB Output is correct
8 Correct 67 ms 5704 KB Output is correct
9 Correct 69 ms 5656 KB Output is correct
10 Correct 54 ms 5684 KB Output is correct
11 Correct 58 ms 5584 KB Output is correct
12 Correct 51 ms 5680 KB Output is correct
13 Correct 55 ms 5660 KB Output is correct
14 Correct 571 ms 53196 KB Output is correct
15 Correct 55 ms 5736 KB Output is correct
16 Correct 524 ms 53320 KB Output is correct
17 Correct 533 ms 53348 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 8 ms 972 KB Output is correct
3 Correct 6 ms 972 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 976 KB Output is correct
17 Correct 57 ms 5608 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 406 ms 41220 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 538 ms 34664 KB Output is correct
31 Correct 518 ms 34604 KB Output is correct
32 Correct 512 ms 53244 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 530 ms 53208 KB Output is correct
35 Correct 569 ms 53296 KB Output is correct
36 Correct 540 ms 53224 KB Output is correct
37 Correct 565 ms 53280 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 51 ms 5680 KB Output is correct
40 Correct 66 ms 5712 KB Output is correct
41 Correct 64 ms 5680 KB Output is correct
42 Correct 67 ms 5684 KB Output is correct
43 Correct 50 ms 5596 KB Output is correct
44 Correct 54 ms 5584 KB Output is correct
45 Correct 52 ms 5680 KB Output is correct
46 Correct 55 ms 5632 KB Output is correct
47 Correct 52 ms 5684 KB Output is correct
48 Correct 55 ms 5684 KB Output is correct
49 Correct 55 ms 5740 KB Output is correct
50 Correct 52 ms 5600 KB Output is correct
51 Correct 535 ms 53232 KB Output is correct
52 Correct 563 ms 53308 KB Output is correct
53 Correct 573 ms 53256 KB Output is correct
54 Correct 56 ms 5680 KB Output is correct
55 Correct 49 ms 5676 KB Output is correct
56 Correct 166 ms 18472 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 64 ms 5588 KB Output is correct
59 Correct 54 ms 5632 KB Output is correct
60 Correct 598 ms 53256 KB Output is correct
61 Correct 53 ms 5680 KB Output is correct
62 Correct 54 ms 5680 KB Output is correct
63 Correct 53 ms 5704 KB Output is correct
64 Correct 67 ms 5704 KB Output is correct
65 Correct 69 ms 5656 KB Output is correct
66 Correct 54 ms 5684 KB Output is correct
67 Correct 58 ms 5584 KB Output is correct
68 Correct 51 ms 5680 KB Output is correct
69 Correct 55 ms 5660 KB Output is correct
70 Correct 571 ms 53196 KB Output is correct
71 Correct 55 ms 5736 KB Output is correct
72 Correct 524 ms 53320 KB Output is correct
73 Correct 533 ms 53348 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 972 KB Output is correct
80 Correct 605 ms 53224 KB Output is correct
81 Correct 602 ms 53508 KB Output is correct
82 Correct 565 ms 53260 KB Output is correct
83 Correct 565 ms 53356 KB Output is correct
84 Correct 562 ms 53192 KB Output is correct
85 Correct 573 ms 53260 KB Output is correct
86 Correct 164 ms 18408 KB Output is correct
87 Correct 1 ms 208 KB Output is correct