Submission #317777

# Submission time Handle Problem Language Result Execution time Memory
317777 2020-10-30T11:17:01 Z tjdgus4384 Strange Device (APIO19_strange_device) C++14
5 / 100
54 ms 4076 KB
#include<bits/stdc++.h>
using namespace std;
long long n, A, B, l[100001], r[100001];
vector<pair<long long, long long> > v;

long long gcd(long long X, long long Y){
    if(X%Y == 0) return Y;
    if(Y%X == 0) return X;
    if(X>Y) return gcd(X%Y, Y);
    if(Y>X) return gcd(Y, Y%X);
}

int main(){
    scanf("%lld %lld %lld", &n, &A, &B);
    for(long long i = 0;i < n;i++){
        scanf("%lld %lld", &l[i], &r[i]);
    }
    long long g = gcd(B+1, A), t;
    bool chk = false;
    if(log10((A/g)) + log10(B) > 18.7) chk = true;
    else t = (A/g) * B;
    for(long long i = 0;i < n;i++){
        if(chk) {
            v.push_back({l[i], r[i]});
            continue;
        }
        if((r[i] - l[i] + 1) >= t){
            printf("%lld", t);
            return 0;
        }
        l[i] %= t;
        r[i] %= t;
        if(r[i] < l[i]){
            v.push_back({l[i], t-1});
            v.push_back({0, r[i]});
        }
        else v.push_back({l[i], r[i]});
    }
    sort(v.begin(), v.end());
    long long s = v[0].first, e = v[0].second, ans = 0;
    for(long long i = 1;i < v.size();i++){
        if(v[i].first <= e) e = max(e, v[i].second);
        else{
            ans += (e-s+1);
            s = v[i].first;
            e = v[i].second;
        }
    }
    ans += e-s+1;
    printf("%lld", ans);
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:41:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(long long i = 1;i < v.size();i++){
      |                         ~~^~~~~~~~~~
strange_device.cpp: In function 'long long int gcd(long long int, long long int)':
strange_device.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
   11 | }
      | ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%lld %lld %lld", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         scanf("%lld %lld", &l[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 5 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Execution timed out 42 ms 1912 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Execution timed out 42 ms 1912 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Execution timed out 42 ms 1912 KB Time limit exceeded (wall clock)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 54 ms 4076 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 5 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -