Submission #821853

# Submission time Handle Problem Language Result Execution time Memory
821853 2023-08-11T19:25:30 Z 7mody Strange Device (APIO19_strange_device) C++17
100 / 100
373 ms 56504 KB
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;

void solve(){
    ll n,a,b; cin >> n >> a >> b;
    vector<pair<ll,ll>> arr(n);
    ll curr=0;
    for(int i=0; i < n;i++){
        cin >> arr[i].first >> arr[i].second;
        curr+=arr[i].second - arr[i].first +1;
    }
    ll x=a/(__gcd(b+1,a));
    ll maxi=x*b;
    if((arr[n-1].second-1)< maxi){
        cout << curr << endl;
        return;
    }
    vector<pair<ll,ll>> ans;
    for(int i=0; i < n;i++){
        if(arr[i].second - arr[i].first +1>=maxi){
            cout << maxi << endl;
            return;
        }
        arr[i].second%=maxi;
        arr[i].first%=maxi;
        if(arr[i].first > arr[i].second){
            ans.push_back({arr[i].first,maxi-1ll});
            ans.push_back({0ll,arr[i].second});
        } else{
            ans.push_back({arr[i].first, arr[i].second});
        }
    }
    sort(ans.begin(),ans.end());
    vector<pair<ll,ll>> add;
    curr=-1;
    for(auto c: ans){
        if(curr==-1){
            curr=0;
            add.push_back(c);
        } else if(c.first > add[curr].second){
            add.push_back(c);
            curr++;
        } else{
            add[curr].second=max(add[curr].second,c.second);
        }
    }
    ll out=0;
    for(auto c : add) out += c.second - c.first +1;
    cout << out << endl;
}

int main(){
    ios::sync_with_stdio(false);cout.tie();cin.tie();
    int t=1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0; i < n;i++){
      |                  ~~^~~
strange_device.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0; i < n;i++){
      |                  ~~^~~
strange_device.cpp:38:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if(curr==-1){
      |            ~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 5 ms 1232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1200 KB Output is correct
17 Correct 49 ms 6664 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 218 ms 32728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 347 ms 56476 KB Output is correct
3 Correct 318 ms 56468 KB Output is correct
4 Correct 317 ms 56472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 347 ms 56476 KB Output is correct
3 Correct 318 ms 56468 KB Output is correct
4 Correct 317 ms 56472 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 343 ms 56492 KB Output is correct
7 Correct 326 ms 56468 KB Output is correct
8 Correct 314 ms 56476 KB Output is correct
9 Correct 337 ms 56476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 347 ms 56476 KB Output is correct
3 Correct 318 ms 56468 KB Output is correct
4 Correct 317 ms 56472 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 31 ms 6748 KB Output is correct
7 Correct 38 ms 6732 KB Output is correct
8 Correct 30 ms 6740 KB Output is correct
9 Correct 31 ms 6748 KB Output is correct
10 Correct 30 ms 6716 KB Output is correct
11 Correct 32 ms 6736 KB Output is correct
12 Correct 30 ms 6752 KB Output is correct
13 Correct 33 ms 6752 KB Output is correct
14 Correct 30 ms 6780 KB Output is correct
15 Correct 36 ms 6748 KB Output is correct
16 Correct 34 ms 6728 KB Output is correct
17 Correct 31 ms 6744 KB Output is correct
18 Correct 316 ms 56504 KB Output is correct
19 Correct 314 ms 56476 KB Output is correct
20 Correct 336 ms 56476 KB Output is correct
21 Correct 33 ms 6724 KB Output is correct
22 Correct 29 ms 6708 KB Output is correct
23 Correct 89 ms 14312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 40 ms 6692 KB Output is correct
3 Correct 34 ms 6748 KB Output is correct
4 Correct 373 ms 56480 KB Output is correct
5 Correct 32 ms 6740 KB Output is correct
6 Correct 33 ms 6788 KB Output is correct
7 Correct 36 ms 6740 KB Output is correct
8 Correct 34 ms 6724 KB Output is correct
9 Correct 33 ms 6724 KB Output is correct
10 Correct 33 ms 6668 KB Output is correct
11 Correct 33 ms 6740 KB Output is correct
12 Correct 29 ms 6736 KB Output is correct
13 Correct 33 ms 6744 KB Output is correct
14 Correct 353 ms 56344 KB Output is correct
15 Correct 33 ms 6544 KB Output is correct
16 Correct 310 ms 56248 KB Output is correct
17 Correct 306 ms 56240 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 5 ms 1232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1200 KB Output is correct
17 Correct 49 ms 6664 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 218 ms 32728 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 347 ms 56476 KB Output is correct
31 Correct 318 ms 56468 KB Output is correct
32 Correct 317 ms 56472 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 343 ms 56492 KB Output is correct
35 Correct 326 ms 56468 KB Output is correct
36 Correct 314 ms 56476 KB Output is correct
37 Correct 337 ms 56476 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 31 ms 6748 KB Output is correct
40 Correct 38 ms 6732 KB Output is correct
41 Correct 30 ms 6740 KB Output is correct
42 Correct 31 ms 6748 KB Output is correct
43 Correct 30 ms 6716 KB Output is correct
44 Correct 32 ms 6736 KB Output is correct
45 Correct 30 ms 6752 KB Output is correct
46 Correct 33 ms 6752 KB Output is correct
47 Correct 30 ms 6780 KB Output is correct
48 Correct 36 ms 6748 KB Output is correct
49 Correct 34 ms 6728 KB Output is correct
50 Correct 31 ms 6744 KB Output is correct
51 Correct 316 ms 56504 KB Output is correct
52 Correct 314 ms 56476 KB Output is correct
53 Correct 336 ms 56476 KB Output is correct
54 Correct 33 ms 6724 KB Output is correct
55 Correct 29 ms 6708 KB Output is correct
56 Correct 89 ms 14312 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 40 ms 6692 KB Output is correct
59 Correct 34 ms 6748 KB Output is correct
60 Correct 373 ms 56480 KB Output is correct
61 Correct 32 ms 6740 KB Output is correct
62 Correct 33 ms 6788 KB Output is correct
63 Correct 36 ms 6740 KB Output is correct
64 Correct 34 ms 6724 KB Output is correct
65 Correct 33 ms 6724 KB Output is correct
66 Correct 33 ms 6668 KB Output is correct
67 Correct 33 ms 6740 KB Output is correct
68 Correct 29 ms 6736 KB Output is correct
69 Correct 33 ms 6744 KB Output is correct
70 Correct 353 ms 56344 KB Output is correct
71 Correct 33 ms 6544 KB Output is correct
72 Correct 310 ms 56248 KB Output is correct
73 Correct 306 ms 56240 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 3 ms 984 KB Output is correct
80 Correct 364 ms 56236 KB Output is correct
81 Correct 370 ms 56220 KB Output is correct
82 Correct 338 ms 56372 KB Output is correct
83 Correct 344 ms 56216 KB Output is correct
84 Correct 335 ms 56256 KB Output is correct
85 Correct 372 ms 56220 KB Output is correct
86 Correct 89 ms 13948 KB Output is correct
87 Correct 0 ms 232 KB Output is correct