Submission #258397

# Submission time Handle Problem Language Result Execution time Memory
258397 2020-08-05T21:25:59 Z DS007 Strange Device (APIO19_strange_device) C++14
35 / 100
813 ms 33600 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, a, b;

bool overflow(int x, int y) {
    int result = x * y;
    if (result / x != y || result / y != x)
        return true;
    return false;
}

int sum() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    return ans;
}

int solveTestCase() {
    cin >> n >> a >> b;

    int temp = a / __gcd(a, b + 1);
    assert(a % __gcd(a, b + 1) == 0);
    if (overflow(temp, b))
        return cout << sum(), 0;

    temp *= b;
    //cerr << temp << "\n";
    vector<pair<int, int>> v;

    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;

        if (r - l + 1 >= temp)
            return cout << temp, 0;

        if (l % temp <= r % temp)
            v.emplace_back(l % temp, 1), v.emplace_back(r % temp + 1, 2);
        else
            v.emplace_back(l % temp, 1), v.emplace_back(temp, 2), v.emplace_back(0, 1), v.emplace_back(r % temp + 1, 2), assert(l % temp > r % temp + 1);
    }

    sort(v.begin(), v.end());

    int ans = 0, d = 0, last = 0;
    for (auto i : v) {
        if (d == 0)
            last = i.first;

        if (i.second == 1)
            d++;
        else
            d--;

        assert(d >= 0);
        if (d == 0)
            ans += i.first - last;
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--)
        solveTestCase();
}


Compilation message

strange_device.cpp: In function 'long long int solveTestCase()':
strange_device.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 7 ms 1152 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 70 ms 4724 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 425 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 614 ms 33472 KB Output is correct
3 Correct 648 ms 33472 KB Output is correct
4 Correct 601 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 614 ms 33472 KB Output is correct
3 Correct 648 ms 33472 KB Output is correct
4 Correct 601 ms 33472 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 632 ms 33512 KB Output is correct
7 Correct 635 ms 33480 KB Output is correct
8 Correct 629 ms 33472 KB Output is correct
9 Correct 761 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 614 ms 33472 KB Output is correct
3 Correct 648 ms 33472 KB Output is correct
4 Correct 601 ms 33472 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 58 ms 4716 KB Output is correct
7 Correct 66 ms 4712 KB Output is correct
8 Correct 57 ms 4716 KB Output is correct
9 Correct 63 ms 4712 KB Output is correct
10 Correct 59 ms 4716 KB Output is correct
11 Correct 62 ms 4844 KB Output is correct
12 Correct 58 ms 4704 KB Output is correct
13 Correct 67 ms 4716 KB Output is correct
14 Correct 63 ms 4716 KB Output is correct
15 Correct 70 ms 4712 KB Output is correct
16 Correct 69 ms 4716 KB Output is correct
17 Correct 59 ms 4716 KB Output is correct
18 Correct 628 ms 33580 KB Output is correct
19 Correct 631 ms 33472 KB Output is correct
20 Correct 748 ms 33596 KB Output is correct
21 Correct 70 ms 4812 KB Output is correct
22 Correct 60 ms 4712 KB Output is correct
23 Correct 173 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 66 ms 4716 KB Output is correct
3 Correct 65 ms 4716 KB Output is correct
4 Correct 813 ms 33472 KB Output is correct
5 Correct 66 ms 4716 KB Output is correct
6 Correct 81 ms 4712 KB Output is correct
7 Correct 66 ms 4716 KB Output is correct
8 Correct 69 ms 4716 KB Output is correct
9 Correct 66 ms 4716 KB Output is correct
10 Correct 73 ms 4872 KB Output is correct
11 Correct 97 ms 4716 KB Output is correct
12 Correct 58 ms 4712 KB Output is correct
13 Correct 109 ms 4708 KB Output is correct
14 Correct 726 ms 33600 KB Output is correct
15 Correct 69 ms 4716 KB Output is correct
16 Correct 595 ms 33428 KB Output is correct
17 Correct 625 ms 33472 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 7 ms 1152 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 70 ms 4724 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't correct