Submission #781542

# Submission time Handle Problem Language Result Execution time Memory
781542 2023-07-13T07:47:34 Z devariaota Strange Device (APIO19_strange_device) C++17
100 / 100
453 ms 93420 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second

ll l[1000005], r[1000005];
vector<pair<ll, ll>> v, ans;

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    /*
    t = xb;
    xb + x = y * a
    x * (b + 1) = y * a
    x = lcm(b + 1, a) / (b + 1)
    a/gcd(b + 1, a) = lcm(b + 1, a) / (b + 1);
    x = a/gcd(b + 1, a)
    banyaknya possibility = x * b -> x = a / gcd(b + 1, a);
    x * b >= r
    b / x
    */
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll x = a / gcd(b + 1, a), sum = 0, ans1 = 0;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
        sum += r[i] - l[i] + 1;
    }
    if ((r[n] - 1) / x < b) {
        cout << sum << "\n";
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        if (r[i] - l[i] + 1 >= x * b) {
            cout << x * b;
            return 0;
        }
        l[i] %= (x * b), r[i] %= (x * b);
        if (l[i] <= r[i]) v.push_back({l[i], r[i]});
        else v.push_back({l[i], x * b - 1}), v.push_back({0, r[i]});
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < (int)v.size(); i++) {
        if (ans.empty()) {
            ans.push_back(v[i]);
            continue;
        }
        if (v[i].fi > ans.back().se) ans.push_back(v[i]);
        else ans.back().se = max(ans.back().se, v[i].se);
    }  
    for (auto u : ans) ans1 += u.se - u.fi + 1;
    cout << ans1 << "\n";
} 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1368 KB Output is correct
3 Correct 4 ms 1368 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1368 KB Output is correct
17 Correct 36 ms 7376 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 225 ms 32996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 337 ms 56480 KB Output is correct
3 Correct 324 ms 56472 KB Output is correct
4 Correct 408 ms 56240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 337 ms 56480 KB Output is correct
3 Correct 324 ms 56472 KB Output is correct
4 Correct 408 ms 56240 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 343 ms 56292 KB Output is correct
7 Correct 336 ms 56236 KB Output is correct
8 Correct 329 ms 56328 KB Output is correct
9 Correct 334 ms 56232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 337 ms 56480 KB Output is correct
3 Correct 324 ms 56472 KB Output is correct
4 Correct 408 ms 56240 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 33 ms 7612 KB Output is correct
7 Correct 35 ms 7496 KB Output is correct
8 Correct 34 ms 7572 KB Output is correct
9 Correct 34 ms 7456 KB Output is correct
10 Correct 33 ms 7524 KB Output is correct
11 Correct 38 ms 7528 KB Output is correct
12 Correct 31 ms 7500 KB Output is correct
13 Correct 34 ms 7564 KB Output is correct
14 Correct 35 ms 7456 KB Output is correct
15 Correct 38 ms 7612 KB Output is correct
16 Correct 41 ms 7568 KB Output is correct
17 Correct 33 ms 7564 KB Output is correct
18 Correct 318 ms 56196 KB Output is correct
19 Correct 314 ms 56344 KB Output is correct
20 Correct 336 ms 56256 KB Output is correct
21 Correct 35 ms 7492 KB Output is correct
22 Correct 31 ms 7564 KB Output is correct
23 Correct 99 ms 15004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 36 ms 7984 KB Output is correct
3 Correct 34 ms 7500 KB Output is correct
4 Correct 367 ms 56252 KB Output is correct
5 Correct 44 ms 7556 KB Output is correct
6 Correct 34 ms 7572 KB Output is correct
7 Correct 33 ms 7500 KB Output is correct
8 Correct 35 ms 7520 KB Output is correct
9 Correct 34 ms 7508 KB Output is correct
10 Correct 35 ms 7504 KB Output is correct
11 Correct 35 ms 7532 KB Output is correct
12 Correct 31 ms 7464 KB Output is correct
13 Correct 43 ms 7668 KB Output is correct
14 Correct 340 ms 56276 KB Output is correct
15 Correct 35 ms 7348 KB Output is correct
16 Correct 317 ms 56244 KB Output is correct
17 Correct 322 ms 56184 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1368 KB Output is correct
3 Correct 4 ms 1368 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1368 KB Output is correct
17 Correct 36 ms 7376 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 225 ms 32996 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 337 ms 56480 KB Output is correct
31 Correct 324 ms 56472 KB Output is correct
32 Correct 408 ms 56240 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 343 ms 56292 KB Output is correct
35 Correct 336 ms 56236 KB Output is correct
36 Correct 329 ms 56328 KB Output is correct
37 Correct 334 ms 56232 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 33 ms 7612 KB Output is correct
40 Correct 35 ms 7496 KB Output is correct
41 Correct 34 ms 7572 KB Output is correct
42 Correct 34 ms 7456 KB Output is correct
43 Correct 33 ms 7524 KB Output is correct
44 Correct 38 ms 7528 KB Output is correct
45 Correct 31 ms 7500 KB Output is correct
46 Correct 34 ms 7564 KB Output is correct
47 Correct 35 ms 7456 KB Output is correct
48 Correct 38 ms 7612 KB Output is correct
49 Correct 41 ms 7568 KB Output is correct
50 Correct 33 ms 7564 KB Output is correct
51 Correct 318 ms 56196 KB Output is correct
52 Correct 314 ms 56344 KB Output is correct
53 Correct 336 ms 56256 KB Output is correct
54 Correct 35 ms 7492 KB Output is correct
55 Correct 31 ms 7564 KB Output is correct
56 Correct 99 ms 15004 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 36 ms 7984 KB Output is correct
59 Correct 34 ms 7500 KB Output is correct
60 Correct 367 ms 56252 KB Output is correct
61 Correct 44 ms 7556 KB Output is correct
62 Correct 34 ms 7572 KB Output is correct
63 Correct 33 ms 7500 KB Output is correct
64 Correct 35 ms 7520 KB Output is correct
65 Correct 34 ms 7508 KB Output is correct
66 Correct 35 ms 7504 KB Output is correct
67 Correct 35 ms 7532 KB Output is correct
68 Correct 31 ms 7464 KB Output is correct
69 Correct 43 ms 7668 KB Output is correct
70 Correct 340 ms 56276 KB Output is correct
71 Correct 35 ms 7348 KB Output is correct
72 Correct 317 ms 56244 KB Output is correct
73 Correct 322 ms 56184 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 324 KB Output is correct
76 Correct 0 ms 340 KB Output is correct
77 Correct 1 ms 332 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 4 ms 1372 KB Output is correct
80 Correct 397 ms 93372 KB Output is correct
81 Correct 453 ms 93360 KB Output is correct
82 Correct 379 ms 93380 KB Output is correct
83 Correct 396 ms 93348 KB Output is correct
84 Correct 352 ms 93408 KB Output is correct
85 Correct 374 ms 93420 KB Output is correct
86 Correct 106 ms 26552 KB Output is correct
87 Correct 1 ms 328 KB Output is correct