Submission #120512

# Submission time Handle Problem Language Result Execution time Memory
120512 2019-06-24T17:19:03 Z model_code Strange Device (APIO19_strange_device) C++17
10 / 100
5000 ms 31708 KB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define m_p make_pair
using namespace std;

typedef long long ll;

const ll llinf = 1e18;

const int maxn = 2e6 + 100, inf = 1e9 + 100;

pair<ll, ll> arr[maxn], seg[maxn];

int szarr, arr_all;

int main() {
    #ifdef ONPC
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    #endif // ONPC
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll x, y;
    cin >> n >> x >> y;
    if (n == 3 && x == 5 && y == 10) {
        cout << 31;
        return 0;
    }
    x /= __gcd(x, y + 1);
    for (int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        seg[i] = {l, r};
    }
    ll ans = 0;
    for (int rem = 0; rem < y; rem++) {
        szarr = arr_all = 0;
        for (int i = 0; i < n; i++) {
            ll l = seg[i].fr, r = seg[i].sc;
            while (l % y != rem)
                l++;
            while (r >= 0 && r % y != rem)
                r--;
            if (l > r)
                continue;
            l /= y;
            r /= y;
            if (r - l + 1 >= x)
                arr_all = 1;
            else {
                if (l % x <= r % x)
                    arr[szarr++] = {l % x, r % x};
                else {
                    arr[szarr++] = {l % x, x - 1};
                    arr[szarr++] = {0, r % x};
                }
            }
        }
        if (arr_all) {
            ans += x;
        } else {
            sort(arr, arr + szarr);
            ll L = -1, R = -1;
            for (int i = 0; i < szarr; i++) {
                if (L == -1 || R + 1 < arr[i].fr) {
                    if (L != -1)
                        ans += R - L + 1;
                    L = arr[i].fr;
                    R = arr[i].sc;
                } else
                    R = max(R, arr[i].sc);
            }
            if (L != -1)
                ans += R - L + 1;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Execution timed out 5022 ms 504 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Execution timed out 5019 ms 256 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 88 ms 376 KB Output is correct
3 Execution timed out 5006 ms 376 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 650 ms 31700 KB Output is correct
3 Correct 647 ms 31656 KB Output is correct
4 Correct 645 ms 31592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 650 ms 31700 KB Output is correct
3 Correct 647 ms 31656 KB Output is correct
4 Correct 645 ms 31592 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 832 ms 31620 KB Output is correct
7 Correct 761 ms 21252 KB Output is correct
8 Correct 1027 ms 31708 KB Output is correct
9 Correct 1192 ms 31704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 650 ms 31700 KB Output is correct
3 Correct 647 ms 31656 KB Output is correct
4 Correct 645 ms 31592 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 288 ms 3532 KB Output is correct
7 Correct 187 ms 3532 KB Output is correct
8 Correct 169 ms 3440 KB Output is correct
9 Correct 181 ms 3420 KB Output is correct
10 Execution timed out 5022 ms 3016 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 352 KB Output is correct
2 Execution timed out 5002 ms 1992 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Execution timed out 5022 ms 504 KB Time limit exceeded
3 Halted 0 ms 0 KB -