Submission #995122

# Submission time Handle Problem Language Result Execution time Memory
995122 2024-06-08T13:27:24 Z mrwang Strange Device (APIO19_strange_device) C++14
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
ll gcd(ll a, ll b){
    return __gcd(a, b);
}
ll get(ll a, ll b){
    ll c = (a / gcd(a, b + 1)), hi = inf / b;
    if(c > hi){
        c = inf;
    }
    else{
        c *= b;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    while(t--){
        ll n, a, b, i, l, r;
        cin >> n >> a >> b;
        if(a == 1 && b == 1){
            cout << 1 << "\n";
        }
        ll x = get(a, b);
        vector<array<ll, 2>> v;
        bool ok = 1;
        for(i = 1; i <= n; i++){
            cin >> l >> r;
            ok &= ((r - l + 1) >= x);
            l %= x;
            r %= x;
            if(r < l){
                v.push_back({l, x - 1});
                v.push_back({0, r});
            }
            else{
                v.push_back({l, r});
            }
        }
        if(ok){
            cout << x << "\n";
        }
        sort(v.begin(), v.end());
        ll s = 0, hi = -1;
        for(i = 0; i < v.size(); i++){
            if(v[i][0] > hi){
                s += (v[i][1] - v[i][0] + 1);
                hi = v[i][1];
            }
            else
            {
                s+=max(0ll,v[i][1]-hi);
                hi=max(hi,v[i][1]);
            }
        }
        cout << s << "\n";
    }
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:51:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -