Submission #721512

# Submission time Handle Problem Language Result Execution time Memory
721512 2023-04-11T03:34:35 Z GrandTiger1729 Strange Device (APIO19_strange_device) C++17
0 / 100
333 ms 16788 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e18 + 10;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    long long A, B; cin >> A >> B;
    if ((__int128_t)1 * A * B / __gcd(A, B + 1) >= INF){
        long long ans = 0;
        for (int i = 0; i < n; i++){
            long long l, r; cin >> l >> r;
            ans += r - l + 1;
        }
        cout << ans << '\n';
        return 0;
    }
    long long D = (__int128_t)1 * A * B / __gcd(A, B + 1);
    vector<pair<long long, long long>> res;
    for (int i = 0; i < n; i++){
        long long l, r; cin >> l >> r;
        r++;
        if (r - l >= D){
            cout << D << '\n';
            return 0;
        }
        long long ll = D * (l / D + bool(l % D)), rr = D * (r / D);
        if (ll > rr){
            res.emplace_back(l, r);
        }else{
            res.emplace_back(l % D, D);
            res.emplace_back(0, r % D);
        }
    }
    long long ans = 0;
    for (int i = 0; i < res.size(); i++)
        ans += res[i].second - res[i].first;
    cout << ans << '\n';
    return 0;
}

Compilation message

strange_device.cpp:4:22: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    4 | const int INF = 1e18 + 10;
      |                 ~~~~~^~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:36: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]
   36 |     for (int i = 0; i < res.size(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 668 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 333 ms 16788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 333 ms 16788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 333 ms 16788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 40 ms 2476 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 668 KB Output isn't correct
3 Halted 0 ms 0 KB -