Submission #317866

# Submission time Handle Problem Language Result Execution time Memory
317866 2020-10-30T15:53:15 Z tjdgus4384 Strange Device (APIO19_strange_device) C++14
15 / 100
61 ms 4204 KB
#include<bits/stdc++.h>
using namespace std;
long long A, B, l[100001], r[100001];
vector<pair<long long, long long> > v;
int n;

int main(){
    scanf("%d %lld %lld", &n, &A, &B);
    for(int i = 0;i < n;i++){
        scanf("%lld %lld", &l[i], &r[i]);
    }
    long long g = __gcd(B+1, A), t = 1000000000000000000LL;    
    if(A/g <= t/B) t = (A/g)*B;
    
    for(int i = 0;i < n;i++){
        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(int 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:30:21: 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]
   30 |     for(int i = 1;i < v.size();i++){
      |                   ~~^~~~~~~~~~
strange_device.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%d %lld %lld", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |         scanf("%lld %lld", &l[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 56 ms 4076 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Execution timed out 35 ms 1928 KB Time limit exceeded (wall clock)
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Execution timed out 43 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 43 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 43 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 Correct 56 ms 4076 KB Output is correct
3 Correct 61 ms 4204 KB Output is correct
4 Execution timed out 42 ms 1912 KB Time limit exceeded (wall clock)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 56 ms 4076 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Execution timed out 35 ms 1928 KB Time limit exceeded (wall clock)