Submission #409657

# Submission time Handle Problem Language Result Execution time Memory
409657 2021-05-21T09:43:49 Z tempus Strange Device (APIO19_strange_device) C++17
5 / 100
594 ms 32452 KB
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"
#define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);

using namespace std;

int main() {
    ios
    int n;
    cin >> n;
    ll A, B;
    cin >> A >> B;
    ll S = 0;
    map <ll, ll> was;
    ll l[n], r[n], ans = 0;
    for (int i = 0; i < n; ++ i) {
        cin >> l[i] >> r[i];
        S += r[i] - l[i] + 1;
    }
    ll cA = A;
    cA /= __gcd(B - 1, A);

    if (B > 2e18 / cA + 1) {
            S = 1 / 0;
        cout << S;
        return 0;
    }
    ll val = A * B / __gcd(B - 1, A);
    vector <pair <ll, ll> > v;
    for (int i = 0; i < n; ++ i) {
        if (l[i] + val <= r[i]) {
            cout << val;
            return 0;
        }
        ll ml = l[i] % val, mr = r[i] % val;
        if (ml <= mr) {
            v.push_back({ml, mr});
        }
        else {
            v.push_back({0, mr});
            v.push_back({ml, val - 1});
        }
    }
    sort(v.begin(), v.end());
    ans = v[0].second - v[0].first + 1;/*
    for (int i = 0; i < v.size(); ++ i) {
        cout << v[i].first << " " << v[i].second << endl;
    }+*/
    for (int i = 1; i < v.size(); ++ i) {
        ll nl = v[i].first, nr = v[i].second;
        if (nl > v[i - 1].second) {
            ans += nr - nl + 1;
            continue;
        }
        else if (nr <= v[i - 1].second) {
            v[i].second = v[i - 1].second;
        }
        else {
            ans += nr - v[i - 1].second;
        }
    }
    cout << ans;
    //3 3 3 4 4 7 9 17 18
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:26:19: warning: division by zero [-Wdiv-by-zero]
   26 |             S = 1 / 0;
      |                 ~~^~~
strange_device.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i = 1; i < v.size(); ++ i) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 6 ms 844 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 204 KB Output isn't 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 362 ms 32452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 387 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 387 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 387 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 51 ms 4028 KB Output is correct
3 Correct 52 ms 4036 KB Output is correct
4 Correct 594 ms 32444 KB Output is correct
5 Correct 50 ms 4040 KB Output is correct
6 Correct 51 ms 4036 KB Output is correct
7 Correct 51 ms 4036 KB Output is correct
8 Correct 51 ms 4040 KB Output is correct
9 Correct 50 ms 4040 KB Output is correct
10 Correct 53 ms 4036 KB Output is correct
11 Correct 51 ms 4028 KB Output is correct
12 Correct 58 ms 4024 KB Output is correct
13 Correct 51 ms 4040 KB Output is correct
14 Correct 531 ms 32436 KB Output is correct
15 Incorrect 50 ms 4032 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 6 ms 844 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -