Submission #317868

# Submission time Handle Problem Language Result Execution time Memory
317868 2020-10-30T16:02:28 Z tjdgus4384 Strange Device (APIO19_strange_device) C++14
100 / 100
639 ms 51936 KB
#include<bits/stdc++.h>
using namespace std;
long long A, B, l[1000001], r[1000001];
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 1 ms 384 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 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 60 ms 4204 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 Correct 423 ms 33884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 532 ms 34780 KB Output is correct
3 Correct 532 ms 38880 KB Output is correct
4 Correct 519 ms 38880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 532 ms 34780 KB Output is correct
3 Correct 532 ms 38880 KB Output is correct
4 Correct 519 ms 38880 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 525 ms 38876 KB Output is correct
7 Correct 529 ms 38876 KB Output is correct
8 Correct 521 ms 38864 KB Output is correct
9 Correct 566 ms 41312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 532 ms 34780 KB Output is correct
3 Correct 532 ms 38880 KB Output is correct
4 Correct 519 ms 38880 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 54 ms 7916 KB Output is correct
7 Correct 56 ms 7788 KB Output is correct
8 Correct 53 ms 7788 KB Output is correct
9 Correct 59 ms 7788 KB Output is correct
10 Correct 57 ms 7788 KB Output is correct
11 Correct 56 ms 7788 KB Output is correct
12 Correct 52 ms 7916 KB Output is correct
13 Correct 56 ms 7788 KB Output is correct
14 Correct 54 ms 7788 KB Output is correct
15 Correct 58 ms 7796 KB Output is correct
16 Correct 58 ms 7916 KB Output is correct
17 Correct 53 ms 7788 KB Output is correct
18 Correct 551 ms 50864 KB Output is correct
19 Correct 513 ms 51160 KB Output is correct
20 Correct 591 ms 51680 KB Output is correct
21 Correct 57 ms 7788 KB Output is correct
22 Correct 49 ms 7788 KB Output is correct
23 Correct 193 ms 26724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 56 ms 4080 KB Output is correct
3 Correct 54 ms 4204 KB Output is correct
4 Correct 639 ms 47736 KB Output is correct
5 Correct 56 ms 7916 KB Output is correct
6 Correct 57 ms 7788 KB Output is correct
7 Correct 57 ms 8044 KB Output is correct
8 Correct 61 ms 7788 KB Output is correct
9 Correct 55 ms 7788 KB Output is correct
10 Correct 57 ms 7788 KB Output is correct
11 Correct 58 ms 7916 KB Output is correct
12 Correct 52 ms 7788 KB Output is correct
13 Correct 58 ms 7788 KB Output is correct
14 Correct 582 ms 42584 KB Output is correct
15 Correct 57 ms 7788 KB Output is correct
16 Correct 546 ms 43000 KB Output is correct
17 Correct 535 ms 38880 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 60 ms 4204 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 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 Correct 423 ms 33884 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 532 ms 34780 KB Output is correct
31 Correct 532 ms 38880 KB Output is correct
32 Correct 519 ms 38880 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 525 ms 38876 KB Output is correct
35 Correct 529 ms 38876 KB Output is correct
36 Correct 521 ms 38864 KB Output is correct
37 Correct 566 ms 41312 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 54 ms 7916 KB Output is correct
40 Correct 56 ms 7788 KB Output is correct
41 Correct 53 ms 7788 KB Output is correct
42 Correct 59 ms 7788 KB Output is correct
43 Correct 57 ms 7788 KB Output is correct
44 Correct 56 ms 7788 KB Output is correct
45 Correct 52 ms 7916 KB Output is correct
46 Correct 56 ms 7788 KB Output is correct
47 Correct 54 ms 7788 KB Output is correct
48 Correct 58 ms 7796 KB Output is correct
49 Correct 58 ms 7916 KB Output is correct
50 Correct 53 ms 7788 KB Output is correct
51 Correct 551 ms 50864 KB Output is correct
52 Correct 513 ms 51160 KB Output is correct
53 Correct 591 ms 51680 KB Output is correct
54 Correct 57 ms 7788 KB Output is correct
55 Correct 49 ms 7788 KB Output is correct
56 Correct 193 ms 26724 KB Output is correct
57 Correct 1 ms 256 KB Output is correct
58 Correct 56 ms 4080 KB Output is correct
59 Correct 54 ms 4204 KB Output is correct
60 Correct 639 ms 47736 KB Output is correct
61 Correct 56 ms 7916 KB Output is correct
62 Correct 57 ms 7788 KB Output is correct
63 Correct 57 ms 8044 KB Output is correct
64 Correct 61 ms 7788 KB Output is correct
65 Correct 55 ms 7788 KB Output is correct
66 Correct 57 ms 7788 KB Output is correct
67 Correct 58 ms 7916 KB Output is correct
68 Correct 52 ms 7788 KB Output is correct
69 Correct 58 ms 7788 KB Output is correct
70 Correct 582 ms 42584 KB Output is correct
71 Correct 57 ms 7788 KB Output is correct
72 Correct 546 ms 43000 KB Output is correct
73 Correct 535 ms 38880 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 6 ms 1280 KB Output is correct
80 Correct 581 ms 40796 KB Output is correct
81 Correct 584 ms 40668 KB Output is correct
82 Correct 565 ms 51936 KB Output is correct
83 Correct 557 ms 38744 KB Output is correct
84 Correct 563 ms 43744 KB Output is correct
85 Correct 571 ms 43744 KB Output is correct
86 Correct 198 ms 26468 KB Output is correct
87 Correct 1 ms 384 KB Output is correct