Submission #398388

# Submission time Handle Problem Language Result Execution time Memory
398388 2021-05-04T08:24:29 Z jack715 Strange Device (APIO19_strange_device) C++14
100 / 100
533 ms 23580 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long

using namespace std;

/*
 ____     __    _______    _______   __________
|     \  |  |  |  _____|  /  _____) |____  ____|
|  |\  \ |  |  | |__     (  (_____      |  |
|  | \  \|  |  |  __|     \_____  \     |  | 
|  |  \     |  | |_____    _____)  )    |  | 
|__|   \____|  |_______|  (_______/     |__| 
*/

int INF = LLONG_MAX;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, A, B, I, gcd, k, l, r;
    cin >> n >> A >> B;
    gcd = __gcd(A, B+1);

    if (gcd == 1) k = A;
    else k = A / gcd;

    if (INF / k <= B) 
        I = INF;
    else 
        I = k*B;

    vector<pair<int, int> > rem;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        if (r-l+1 >= I) {
            rem.pb({0, I-1});
        } else if (l%I > r%I) {
            rem.pb({l%I, I-1});
            rem.pb({0, r%I});
        } else {
            rem.pb({l%I, r%I});
        } 
    }

    int L = 0, ans = 0;
    sort(rem.begin(), rem.end());
    for (auto el : rem) {
        el.ff = max(el.ff, L);
        if (el.ff > el.ss)
            continue;
        ans += el.ss-el.ff+1;
        L = max(L, el.ss+1);
    }
    cout << ans << '\n';
    return 0;
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 59 ms 2492 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 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 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 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 337 ms 16868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 482 ms 16912 KB Output is correct
3 Correct 446 ms 16844 KB Output is correct
4 Correct 460 ms 16808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 482 ms 16912 KB Output is correct
3 Correct 446 ms 16844 KB Output is correct
4 Correct 460 ms 16808 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 469 ms 16760 KB Output is correct
7 Correct 457 ms 16856 KB Output is correct
8 Correct 455 ms 16832 KB Output is correct
9 Correct 495 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 482 ms 16912 KB Output is correct
3 Correct 446 ms 16844 KB Output is correct
4 Correct 460 ms 16808 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 44 ms 2424 KB Output is correct
7 Correct 47 ms 2484 KB Output is correct
8 Correct 44 ms 2476 KB Output is correct
9 Correct 45 ms 2492 KB Output is correct
10 Correct 44 ms 2476 KB Output is correct
11 Correct 46 ms 2496 KB Output is correct
12 Correct 43 ms 2384 KB Output is correct
13 Correct 54 ms 2392 KB Output is correct
14 Correct 44 ms 2496 KB Output is correct
15 Correct 51 ms 2464 KB Output is correct
16 Correct 46 ms 2492 KB Output is correct
17 Correct 44 ms 2504 KB Output is correct
18 Correct 455 ms 16780 KB Output is correct
19 Correct 436 ms 16972 KB Output is correct
20 Correct 494 ms 16888 KB Output is correct
21 Correct 47 ms 2496 KB Output is correct
22 Correct 45 ms 2504 KB Output is correct
23 Correct 138 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 47 ms 2504 KB Output is correct
3 Correct 49 ms 2404 KB Output is correct
4 Correct 516 ms 16864 KB Output is correct
5 Correct 46 ms 2504 KB Output is correct
6 Correct 46 ms 2436 KB Output is correct
7 Correct 47 ms 2440 KB Output is correct
8 Correct 50 ms 2500 KB Output is correct
9 Correct 47 ms 2480 KB Output is correct
10 Correct 47 ms 2504 KB Output is correct
11 Correct 47 ms 2436 KB Output is correct
12 Correct 42 ms 2428 KB Output is correct
13 Correct 47 ms 2496 KB Output is correct
14 Correct 492 ms 16932 KB Output is correct
15 Correct 48 ms 2492 KB Output is correct
16 Correct 490 ms 16768 KB Output is correct
17 Correct 448 ms 16808 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 5 ms 716 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 59 ms 2492 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 337 ms 16868 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 482 ms 16912 KB Output is correct
31 Correct 446 ms 16844 KB Output is correct
32 Correct 460 ms 16808 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 469 ms 16760 KB Output is correct
35 Correct 457 ms 16856 KB Output is correct
36 Correct 455 ms 16832 KB Output is correct
37 Correct 495 ms 16984 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 44 ms 2424 KB Output is correct
40 Correct 47 ms 2484 KB Output is correct
41 Correct 44 ms 2476 KB Output is correct
42 Correct 45 ms 2492 KB Output is correct
43 Correct 44 ms 2476 KB Output is correct
44 Correct 46 ms 2496 KB Output is correct
45 Correct 43 ms 2384 KB Output is correct
46 Correct 54 ms 2392 KB Output is correct
47 Correct 44 ms 2496 KB Output is correct
48 Correct 51 ms 2464 KB Output is correct
49 Correct 46 ms 2492 KB Output is correct
50 Correct 44 ms 2504 KB Output is correct
51 Correct 455 ms 16780 KB Output is correct
52 Correct 436 ms 16972 KB Output is correct
53 Correct 494 ms 16888 KB Output is correct
54 Correct 47 ms 2496 KB Output is correct
55 Correct 45 ms 2504 KB Output is correct
56 Correct 138 ms 8536 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 47 ms 2504 KB Output is correct
59 Correct 49 ms 2404 KB Output is correct
60 Correct 516 ms 16864 KB Output is correct
61 Correct 46 ms 2504 KB Output is correct
62 Correct 46 ms 2436 KB Output is correct
63 Correct 47 ms 2440 KB Output is correct
64 Correct 50 ms 2500 KB Output is correct
65 Correct 47 ms 2480 KB Output is correct
66 Correct 47 ms 2504 KB Output is correct
67 Correct 47 ms 2436 KB Output is correct
68 Correct 42 ms 2428 KB Output is correct
69 Correct 47 ms 2496 KB Output is correct
70 Correct 492 ms 16932 KB Output is correct
71 Correct 48 ms 2492 KB Output is correct
72 Correct 490 ms 16768 KB Output is correct
73 Correct 448 ms 16808 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 5 ms 968 KB Output is correct
80 Correct 533 ms 18640 KB Output is correct
81 Correct 516 ms 18820 KB Output is correct
82 Correct 492 ms 22872 KB Output is correct
83 Correct 486 ms 23580 KB Output is correct
84 Correct 488 ms 21396 KB Output is correct
85 Correct 488 ms 17084 KB Output is correct
86 Correct 139 ms 8956 KB Output is correct
87 Correct 1 ms 204 KB Output is correct