Submission #391265

# Submission time Handle Problem Language Result Execution time Memory
391265 2021-04-18T10:54:30 Z phathnv Strange Device (APIO19_strange_device) C++11
20 / 100
562 ms 53264 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
ll a, b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> a >> b;

    ll k = a / __gcd(a, b + 1);
    ll cycle = 0;
    if (b > 2e18 / k)
        cycle = 2e18;
    else
        cycle = b * k;

    vector<pair<int, int>> e;
    auto addSegment = [&](int l, int r){
        e.push_back({l, 1});
        e.push_back({r + 1, -1});
    };
    for(int i = 1; i <= n; i++){
        ll l, r;
        cin >> l >> r;
        if (r - l + 1 >= cycle){
            cout << cycle;
            return 0;
        }
        l %= cycle;
        r %= cycle;
        if (l <= r){
            addSegment(l, r);
        } else {
            addSegment(l, cycle - 1);
            addSegment(0, r);
        }
    }
    sort(e.begin(), e.end());
    int cnt = 0;
    ll res = 0, last = 0;
    for(auto p : e){
        if (p.first != last){
            res += (cnt > 0) * (p.first - last);
            last = p.first;
        }
        cnt += p.second;
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 7 ms 980 KB Output is correct
3 Correct 6 ms 968 KB Output is correct
4 Correct 1 ms 204 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 208 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 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 65 ms 5688 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 404 ms 41248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 562 ms 53256 KB Output is correct
3 Incorrect 533 ms 53264 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 562 ms 53256 KB Output is correct
3 Incorrect 533 ms 53264 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 562 ms 53256 KB Output is correct
3 Incorrect 533 ms 53264 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 61 ms 5604 KB Output is correct
3 Incorrect 56 ms 5628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 7 ms 980 KB Output is correct
3 Correct 6 ms 968 KB Output is correct
4 Correct 1 ms 204 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 208 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 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 65 ms 5688 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 404 ms 41248 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 562 ms 53256 KB Output is correct
31 Incorrect 533 ms 53264 KB Output isn't correct
32 Halted 0 ms 0 KB -