Submission #934706

# Submission time Handle Problem Language Result Execution time Memory
934706 2024-02-27T20:21:44 Z haxorman Strange Device (APIO19_strange_device) C++14
100 / 100
385 ms 53920 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 1e6 + 7;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n, a, b;
    cin >> n >> a >> b;

    __int128 p = a;
    p *= b;
    p /= __gcd(a, b+1);
    
    int ans = 0;
    vector<pair<int,int>> ranges;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        if (r - l + 1 >= p) {
            ans = p;
        }
        l %= p, r %= p;

        if (r < l) {
            ranges.push_back({l, p-1});
            ranges.push_back({0, r});
        }
        else {
            ranges.push_back({l, r});
        }
    }

    if (ans == p) {
        cout << ans << "\n";
        exit(0);
    }
    sort(ranges.begin(), ranges.end());
    
    auto [l, r] = ranges[0];
    for (int i = 1; i < ranges.size(); ++i) {
        auto [lb, rb] = ranges[i];
        
        if (lb <= r) {
            r = max(r, rb);
        }
        else {
            ans += r - l + 1;
            l = lb, r = rb;
        }
    }
    ans += r - l + 1;
    cout << ans << "\n";
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:44:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     auto [l, r] = ranges[0];
      |          ^
strange_device.cpp:45:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 1; i < ranges.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
strange_device.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |         auto [lb, rb] = ranges[i];
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1116 KB Output is correct
17 Correct 33 ms 5864 KB Output is correct
18 Correct 0 ms 344 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 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 203 ms 41228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 312 ms 53812 KB Output is correct
3 Correct 289 ms 53920 KB Output is correct
4 Correct 295 ms 53576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 312 ms 53812 KB Output is correct
3 Correct 289 ms 53920 KB Output is correct
4 Correct 295 ms 53576 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 309 ms 53316 KB Output is correct
7 Correct 302 ms 53264 KB Output is correct
8 Correct 300 ms 53540 KB Output is correct
9 Correct 353 ms 53152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 312 ms 53812 KB Output is correct
3 Correct 289 ms 53920 KB Output is correct
4 Correct 295 ms 53576 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 5792 KB Output is correct
7 Correct 32 ms 5844 KB Output is correct
8 Correct 30 ms 5844 KB Output is correct
9 Correct 31 ms 5616 KB Output is correct
10 Correct 33 ms 5852 KB Output is correct
11 Correct 31 ms 5832 KB Output is correct
12 Correct 31 ms 5700 KB Output is correct
13 Correct 32 ms 5840 KB Output is correct
14 Correct 29 ms 5740 KB Output is correct
15 Correct 33 ms 5832 KB Output is correct
16 Correct 32 ms 5832 KB Output is correct
17 Correct 30 ms 5804 KB Output is correct
18 Correct 299 ms 53020 KB Output is correct
19 Correct 310 ms 53264 KB Output is correct
20 Correct 322 ms 53120 KB Output is correct
21 Correct 32 ms 5832 KB Output is correct
22 Correct 28 ms 5972 KB Output is correct
23 Correct 89 ms 20156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 33 ms 5844 KB Output is correct
3 Correct 40 ms 5832 KB Output is correct
4 Correct 355 ms 53080 KB Output is correct
5 Correct 31 ms 5844 KB Output is correct
6 Correct 32 ms 5844 KB Output is correct
7 Correct 32 ms 5836 KB Output is correct
8 Correct 33 ms 5832 KB Output is correct
9 Correct 48 ms 5840 KB Output is correct
10 Correct 40 ms 5832 KB Output is correct
11 Correct 40 ms 5832 KB Output is correct
12 Correct 44 ms 5828 KB Output is correct
13 Correct 32 ms 5764 KB Output is correct
14 Correct 347 ms 53472 KB Output is correct
15 Correct 35 ms 5876 KB Output is correct
16 Correct 324 ms 53660 KB Output is correct
17 Correct 304 ms 53144 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 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1116 KB Output is correct
17 Correct 33 ms 5864 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 203 ms 41228 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 312 ms 53812 KB Output is correct
31 Correct 289 ms 53920 KB Output is correct
32 Correct 295 ms 53576 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 309 ms 53316 KB Output is correct
35 Correct 302 ms 53264 KB Output is correct
36 Correct 300 ms 53540 KB Output is correct
37 Correct 353 ms 53152 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 38 ms 5792 KB Output is correct
40 Correct 32 ms 5844 KB Output is correct
41 Correct 30 ms 5844 KB Output is correct
42 Correct 31 ms 5616 KB Output is correct
43 Correct 33 ms 5852 KB Output is correct
44 Correct 31 ms 5832 KB Output is correct
45 Correct 31 ms 5700 KB Output is correct
46 Correct 32 ms 5840 KB Output is correct
47 Correct 29 ms 5740 KB Output is correct
48 Correct 33 ms 5832 KB Output is correct
49 Correct 32 ms 5832 KB Output is correct
50 Correct 30 ms 5804 KB Output is correct
51 Correct 299 ms 53020 KB Output is correct
52 Correct 310 ms 53264 KB Output is correct
53 Correct 322 ms 53120 KB Output is correct
54 Correct 32 ms 5832 KB Output is correct
55 Correct 28 ms 5972 KB Output is correct
56 Correct 89 ms 20156 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 33 ms 5844 KB Output is correct
59 Correct 40 ms 5832 KB Output is correct
60 Correct 355 ms 53080 KB Output is correct
61 Correct 31 ms 5844 KB Output is correct
62 Correct 32 ms 5844 KB Output is correct
63 Correct 32 ms 5836 KB Output is correct
64 Correct 33 ms 5832 KB Output is correct
65 Correct 48 ms 5840 KB Output is correct
66 Correct 40 ms 5832 KB Output is correct
67 Correct 40 ms 5832 KB Output is correct
68 Correct 44 ms 5828 KB Output is correct
69 Correct 32 ms 5764 KB Output is correct
70 Correct 347 ms 53472 KB Output is correct
71 Correct 35 ms 5876 KB Output is correct
72 Correct 324 ms 53660 KB Output is correct
73 Correct 304 ms 53144 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 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 456 KB Output is correct
79 Correct 5 ms 1116 KB Output is correct
80 Correct 385 ms 52912 KB Output is correct
81 Correct 369 ms 53300 KB Output is correct
82 Correct 351 ms 53252 KB Output is correct
83 Correct 368 ms 53240 KB Output is correct
84 Correct 349 ms 53228 KB Output is correct
85 Correct 365 ms 53196 KB Output is correct
86 Correct 107 ms 19932 KB Output is correct
87 Correct 0 ms 348 KB Output is correct