Submission #672849

# Submission time Handle Problem Language Result Execution time Memory
672849 2022-12-18T12:30:39 Z ParsaS Strange Device (APIO19_strange_device) C++17
100 / 100
943 ms 100136 KB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 2e5 + 5;
ll A, B;
int n;

void solve() {
    cin >> n >> A >> B;
    ll C = __gcd(A, B + 1);
    ll Ap = A / C;
    ll M;
    if ((ll)1e18 / B < Ap) {
        M = 1e18 + 1;
    }
    else
        M = B * Ap;
    /*ll g = __gcd(Ap, B);
    ll M;
    if (B > 1e9 || (ll)1e18 / (B * B) < (Ap / g))
        M = 1e18 + 1;
    else {
        M = Ap / g * B * B;
    }*/
    bool ok = false;
   /* for (int i = 1; i < 100; i++) {
        if ((i + i / B) % A == 0 && i % B == 0) {
            cout << i << endl;
        }
    }*/
    map<ll, int> vec;
    for (int i = 0; i < n; i++) {
        ll l, r; cin >> l >> r;
        if (r - l >= M) {
            ok = true;
        }
        l %= M, r %= M;
        vec[l]++;
        vec[r + 1]--;
        if (l > r) {
            vec[0]++;
            vec[M]--;
        }
    }
    if (ok) {
        cout << M << '\n';
        return;
    }
    ll prv = 0;
    ll sum = 0, ans = 0;
    for (auto [x, y] : vec) {
        bool tmpp = sum;
        sum += y;
        if (tmpp)
            ans += x - prv;
        if (sum)
            prv = x;
    }
    cout << ans << '\n';
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1272 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1228 KB Output is correct
17 Correct 62 ms 10296 KB Output is correct
18 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 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 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 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 359 ms 25420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 655 ms 100136 KB Output is correct
3 Correct 700 ms 100120 KB Output is correct
4 Correct 825 ms 100024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 655 ms 100136 KB Output is correct
3 Correct 700 ms 100120 KB Output is correct
4 Correct 825 ms 100024 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 690 ms 99740 KB Output is correct
7 Correct 752 ms 99768 KB Output is correct
8 Correct 718 ms 99792 KB Output is correct
9 Correct 789 ms 99256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 655 ms 100136 KB Output is correct
3 Correct 700 ms 100120 KB Output is correct
4 Correct 825 ms 100024 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 62 ms 10288 KB Output is correct
7 Correct 57 ms 10260 KB Output is correct
8 Correct 62 ms 10236 KB Output is correct
9 Correct 63 ms 10260 KB Output is correct
10 Correct 59 ms 10312 KB Output is correct
11 Correct 75 ms 10188 KB Output is correct
12 Correct 68 ms 10300 KB Output is correct
13 Correct 64 ms 10400 KB Output is correct
14 Correct 56 ms 10208 KB Output is correct
15 Correct 71 ms 10188 KB Output is correct
16 Correct 83 ms 10272 KB Output is correct
17 Correct 73 ms 10208 KB Output is correct
18 Correct 776 ms 99672 KB Output is correct
19 Correct 809 ms 99244 KB Output is correct
20 Correct 802 ms 98868 KB Output is correct
21 Correct 71 ms 10200 KB Output is correct
22 Correct 78 ms 10188 KB Output is correct
23 Correct 141 ms 12908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 73 ms 10304 KB Output is correct
3 Correct 78 ms 10260 KB Output is correct
4 Correct 877 ms 98900 KB Output is correct
5 Correct 74 ms 10216 KB Output is correct
6 Correct 71 ms 10224 KB Output is correct
7 Correct 89 ms 10240 KB Output is correct
8 Correct 77 ms 10304 KB Output is correct
9 Correct 68 ms 10188 KB Output is correct
10 Correct 68 ms 10200 KB Output is correct
11 Correct 69 ms 10200 KB Output is correct
12 Correct 92 ms 10288 KB Output is correct
13 Correct 78 ms 10292 KB Output is correct
14 Correct 888 ms 98876 KB Output is correct
15 Correct 72 ms 10188 KB Output is correct
16 Correct 704 ms 98808 KB Output is correct
17 Correct 800 ms 98776 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 6 ms 1272 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1228 KB Output is correct
17 Correct 62 ms 10296 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 359 ms 25420 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 655 ms 100136 KB Output is correct
31 Correct 700 ms 100120 KB Output is correct
32 Correct 825 ms 100024 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 690 ms 99740 KB Output is correct
35 Correct 752 ms 99768 KB Output is correct
36 Correct 718 ms 99792 KB Output is correct
37 Correct 789 ms 99256 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 62 ms 10288 KB Output is correct
40 Correct 57 ms 10260 KB Output is correct
41 Correct 62 ms 10236 KB Output is correct
42 Correct 63 ms 10260 KB Output is correct
43 Correct 59 ms 10312 KB Output is correct
44 Correct 75 ms 10188 KB Output is correct
45 Correct 68 ms 10300 KB Output is correct
46 Correct 64 ms 10400 KB Output is correct
47 Correct 56 ms 10208 KB Output is correct
48 Correct 71 ms 10188 KB Output is correct
49 Correct 83 ms 10272 KB Output is correct
50 Correct 73 ms 10208 KB Output is correct
51 Correct 776 ms 99672 KB Output is correct
52 Correct 809 ms 99244 KB Output is correct
53 Correct 802 ms 98868 KB Output is correct
54 Correct 71 ms 10200 KB Output is correct
55 Correct 78 ms 10188 KB Output is correct
56 Correct 141 ms 12908 KB Output is correct
57 Correct 1 ms 320 KB Output is correct
58 Correct 73 ms 10304 KB Output is correct
59 Correct 78 ms 10260 KB Output is correct
60 Correct 877 ms 98900 KB Output is correct
61 Correct 74 ms 10216 KB Output is correct
62 Correct 71 ms 10224 KB Output is correct
63 Correct 89 ms 10240 KB Output is correct
64 Correct 77 ms 10304 KB Output is correct
65 Correct 68 ms 10188 KB Output is correct
66 Correct 68 ms 10200 KB Output is correct
67 Correct 69 ms 10200 KB Output is correct
68 Correct 92 ms 10288 KB Output is correct
69 Correct 78 ms 10292 KB Output is correct
70 Correct 888 ms 98876 KB Output is correct
71 Correct 72 ms 10188 KB Output is correct
72 Correct 704 ms 98808 KB Output is correct
73 Correct 800 ms 98776 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 324 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 316 KB Output is correct
79 Correct 7 ms 1228 KB Output is correct
80 Correct 902 ms 98820 KB Output is correct
81 Correct 939 ms 99120 KB Output is correct
82 Correct 860 ms 98956 KB Output is correct
83 Correct 897 ms 98748 KB Output is correct
84 Correct 943 ms 98808 KB Output is correct
85 Correct 940 ms 98808 KB Output is correct
86 Correct 132 ms 12840 KB Output is correct
87 Correct 1 ms 312 KB Output is correct