Submission #654688

# Submission time Handle Problem Language Result Execution time Memory
654688 2022-11-01T09:05:48 Z horiseun Strange Device (APIO19_strange_device) C++11
35 / 100
582 ms 67316 KB
#include <iostream>
#include <vector>
#include <set>
#include <tuple>
#include <algorithm>
using namespace std;

#define ll long long
#define f first
#define s second

ll a, b, n, l, r, p, ans, c, lft;
vector<pair<ll, int>> v;

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> a >> b;
    p = b * (a / gcd(a, b + 1));
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        if (r - l >= p) {
            cout << p << "\n";
            return 0;
        }
        if ((l + p - 1) % p > (r + p - 1) % p) {
            v.push_back({1, 0});
            v.push_back({(l + p - 1) % p + 1, 0});
            v.push_back({(r + p - 1) % p + 1, 1});
            v.push_back({p, 1});
        } else {
            v.push_back({(l + p - 1) % p + 1, 0});
            v.push_back({(r + p - 1) % p + 1, 1});
        }
    }
    sort(v.begin(), v.end());

    lft = -1;
    for (pair<ll, int> i : v) {
        if (!i.s) {
            c++;
            if (lft == -1) lft = i.f;
        } else {
            c--;
            if (c == 0) {
                ans += (i.f - lft + 1);
                lft = -1;
            }
        }
    }
    cout << ans << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1304 KB Output is correct
3 Correct 5 ms 1240 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 316 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 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1344 KB Output is correct
17 Correct 54 ms 5664 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 400 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 472 ms 67316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 484 ms 33784 KB Output is correct
3 Correct 491 ms 34808 KB Output is correct
4 Correct 471 ms 34768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 484 ms 33784 KB Output is correct
3 Correct 491 ms 34808 KB Output is correct
4 Correct 471 ms 34768 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 483 ms 34832 KB Output is correct
7 Correct 485 ms 34916 KB Output is correct
8 Correct 473 ms 34756 KB Output is correct
9 Correct 540 ms 34692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 484 ms 33784 KB Output is correct
3 Correct 491 ms 34808 KB Output is correct
4 Correct 471 ms 34768 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 59 ms 7216 KB Output is correct
7 Correct 51 ms 7292 KB Output is correct
8 Correct 50 ms 7260 KB Output is correct
9 Correct 51 ms 7228 KB Output is correct
10 Correct 50 ms 7232 KB Output is correct
11 Correct 49 ms 7276 KB Output is correct
12 Correct 46 ms 7184 KB Output is correct
13 Correct 52 ms 7256 KB Output is correct
14 Correct 46 ms 7180 KB Output is correct
15 Correct 52 ms 7204 KB Output is correct
16 Correct 60 ms 7296 KB Output is correct
17 Correct 58 ms 7292 KB Output is correct
18 Correct 474 ms 34656 KB Output is correct
19 Correct 468 ms 34704 KB Output is correct
20 Correct 562 ms 34584 KB Output is correct
21 Correct 58 ms 7172 KB Output is correct
22 Correct 44 ms 7180 KB Output is correct
23 Correct 178 ms 38836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 51 ms 7240 KB Output is correct
3 Correct 54 ms 7388 KB Output is correct
4 Correct 582 ms 34496 KB Output is correct
5 Correct 52 ms 7272 KB Output is correct
6 Correct 50 ms 7276 KB Output is correct
7 Correct 51 ms 7244 KB Output is correct
8 Correct 53 ms 7280 KB Output is correct
9 Correct 50 ms 7220 KB Output is correct
10 Correct 55 ms 7188 KB Output is correct
11 Correct 53 ms 7260 KB Output is correct
12 Correct 49 ms 7320 KB Output is correct
13 Correct 54 ms 7228 KB Output is correct
14 Correct 543 ms 34176 KB Output is correct
15 Correct 56 ms 7276 KB Output is correct
16 Correct 442 ms 33868 KB Output is correct
17 Correct 461 ms 33560 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1304 KB Output is correct
3 Correct 5 ms 1240 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 316 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 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1344 KB Output is correct
17 Correct 54 ms 5664 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -