Submission #663200

# Submission time Handle Problem Language Result Execution time Memory
663200 2022-11-26T16:37:28 Z Ai7081 Strange Device (APIO19_strange_device) C++17
0 / 100
305 ms 312 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>

const ll inf = 2e18;

ll n, a, b, l, r, p;
vector<pii> v;

ll gcd(ll c1, ll c2) {
    if (!c2) return c1;
    return gcd(c2, c1%c2);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> a >> b;
    p = (inf/b>a ? a*b : inf);
    bool done = true;
    while (n--) {
        cin >> l >> r;
        if (done) continue;
        if (r-l >= p) {done = true; continue;}
        l%=p, r%=p;
        if (l>r) v.push_back({0, r}), v.push_back({l, p-1});
        else v.push_back({l, r});
    }
    if (done) {cout << p; return 0;}
    sort(v.begin(), v.end());
    ll out=0, ma=-1;
    for (auto [x,y]:v) out += (ma<x ? y-x+1 : max((ll)0, y-ma)), ma=max(ma, y);
    cout << out;
    return 0;
}

/*
3 3 3
4 4
7 9
17 18
ans: 4

3 5 10
1 20
50 68
89 98
ans: 31

1 1000000000000000 1000000000000000000
100000 1000000
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 305 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 305 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 305 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 34 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -