Submission #261513

# Submission time Handle Problem Language Result Execution time Memory
261513 2020-08-11T20:03:48 Z Kastanda Strange Device (APIO19_strange_device) C++11
100 / 100
657 ms 41276 KB
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
int n;
ll A, B, K;
int main()
{
    scanf("%d%lld%lld", &n, &A, &B);
    ll K = A / __gcd(A, B + 1);
    if ((long double)K * B < 2e18)
        K *= B;
    else
        K = (ll)(2e18);
    vector < pii > vec;
    for (int i = 0; i < n; i ++)
    {
        ll l, r;
        scanf("%lld%lld", &l, &r);
        if (r - l + 1 >= K)
            return !printf("%lld\n", K);
        if (l % K <= r % K)
            vec.pb(pii(l % K, r % K));
        else
            vec.pb(pii(l % K, K - 1)), vec.pb(pii(0, r % K));
    }
    sort(vec.begin(), vec.end());
    ll tot = 0, r = -1;
    for (pii X : vec)
    {
        X.y ++;
        if (r >= X.y)
            continue;
        if (r < X.x)
            r = X.x;
        tot += X.y - r;
        r = X.y;
    }
    return !printf("%lld\n", tot);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld%lld", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 68 ms 5720 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 483 ms 41276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 578 ms 34512 KB Output is correct
3 Correct 583 ms 34492 KB Output is correct
4 Correct 583 ms 34496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 578 ms 34512 KB Output is correct
3 Correct 583 ms 34492 KB Output is correct
4 Correct 583 ms 34496 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 589 ms 34512 KB Output is correct
7 Correct 582 ms 34512 KB Output is correct
8 Correct 598 ms 34520 KB Output is correct
9 Correct 640 ms 34512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 578 ms 34512 KB Output is correct
3 Correct 583 ms 34492 KB Output is correct
4 Correct 583 ms 34496 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 72 ms 5732 KB Output is correct
7 Correct 64 ms 5736 KB Output is correct
8 Correct 55 ms 5736 KB Output is correct
9 Correct 75 ms 5736 KB Output is correct
10 Correct 75 ms 5732 KB Output is correct
11 Correct 60 ms 5736 KB Output is correct
12 Correct 56 ms 5660 KB Output is correct
13 Correct 60 ms 5768 KB Output is correct
14 Correct 57 ms 5736 KB Output is correct
15 Correct 79 ms 5736 KB Output is correct
16 Correct 67 ms 5860 KB Output is correct
17 Correct 57 ms 5732 KB Output is correct
18 Correct 613 ms 34516 KB Output is correct
19 Correct 553 ms 34432 KB Output is correct
20 Correct 628 ms 34384 KB Output is correct
21 Correct 62 ms 5732 KB Output is correct
22 Correct 57 ms 5732 KB Output is correct
23 Correct 208 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 61 ms 5696 KB Output is correct
3 Correct 60 ms 5732 KB Output is correct
4 Correct 629 ms 33724 KB Output is correct
5 Correct 60 ms 5768 KB Output is correct
6 Correct 60 ms 5732 KB Output is correct
7 Correct 65 ms 5772 KB Output is correct
8 Correct 63 ms 5736 KB Output is correct
9 Correct 58 ms 5756 KB Output is correct
10 Correct 69 ms 5736 KB Output is correct
11 Correct 69 ms 5732 KB Output is correct
12 Correct 52 ms 5736 KB Output is correct
13 Correct 61 ms 5732 KB Output is correct
14 Correct 646 ms 33596 KB Output is correct
15 Correct 67 ms 5732 KB Output is correct
16 Correct 580 ms 34260 KB Output is correct
17 Correct 569 ms 34000 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 68 ms 5720 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 483 ms 41276 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 578 ms 34512 KB Output is correct
31 Correct 583 ms 34492 KB Output is correct
32 Correct 583 ms 34496 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 589 ms 34512 KB Output is correct
35 Correct 582 ms 34512 KB Output is correct
36 Correct 598 ms 34520 KB Output is correct
37 Correct 640 ms 34512 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 72 ms 5732 KB Output is correct
40 Correct 64 ms 5736 KB Output is correct
41 Correct 55 ms 5736 KB Output is correct
42 Correct 75 ms 5736 KB Output is correct
43 Correct 75 ms 5732 KB Output is correct
44 Correct 60 ms 5736 KB Output is correct
45 Correct 56 ms 5660 KB Output is correct
46 Correct 60 ms 5768 KB Output is correct
47 Correct 57 ms 5736 KB Output is correct
48 Correct 79 ms 5736 KB Output is correct
49 Correct 67 ms 5860 KB Output is correct
50 Correct 57 ms 5732 KB Output is correct
51 Correct 613 ms 34516 KB Output is correct
52 Correct 553 ms 34432 KB Output is correct
53 Correct 628 ms 34384 KB Output is correct
54 Correct 62 ms 5732 KB Output is correct
55 Correct 57 ms 5732 KB Output is correct
56 Correct 208 ms 18524 KB Output is correct
57 Correct 1 ms 256 KB Output is correct
58 Correct 61 ms 5696 KB Output is correct
59 Correct 60 ms 5732 KB Output is correct
60 Correct 629 ms 33724 KB Output is correct
61 Correct 60 ms 5768 KB Output is correct
62 Correct 60 ms 5732 KB Output is correct
63 Correct 65 ms 5772 KB Output is correct
64 Correct 63 ms 5736 KB Output is correct
65 Correct 58 ms 5756 KB Output is correct
66 Correct 69 ms 5736 KB Output is correct
67 Correct 69 ms 5732 KB Output is correct
68 Correct 52 ms 5736 KB Output is correct
69 Correct 61 ms 5732 KB Output is correct
70 Correct 646 ms 33596 KB Output is correct
71 Correct 67 ms 5732 KB Output is correct
72 Correct 580 ms 34260 KB Output is correct
73 Correct 569 ms 34000 KB Output is correct
74 Correct 1 ms 256 KB Output is correct
75 Correct 1 ms 256 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 6 ms 1024 KB Output is correct
80 Correct 635 ms 33432 KB Output is correct
81 Correct 635 ms 33340 KB Output is correct
82 Correct 621 ms 33912 KB Output is correct
83 Correct 603 ms 33744 KB Output is correct
84 Correct 657 ms 33744 KB Output is correct
85 Correct 618 ms 33616 KB Output is correct
86 Correct 210 ms 18524 KB Output is correct
87 Correct 1 ms 256 KB Output is correct