Submission #1044617

# Submission time Handle Problem Language Result Execution time Memory
1044617 2024-08-05T11:44:09 Z vjudge1 Strange Device (APIO19_strange_device) C++17
5 / 100
233 ms 18624 KB
#include "bits/stdc++.h"
using namespace std;

#define int int64_t    
#define pb push_back

using lint=__int128_t;

const int lim=200100;
const int mod=1e9+7;

using pii=pair<int,int>;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
    int n,a,b;
    cin>>n>>a>>b;
    lint cntofdif;
    if((b+1)%a==0){
        cntofdif=b;
    }else{
        cntofdif=a/__gcd(a,(b+1));
        cntofdif*=b;
        cntofdif=min<lint>(cntofdif,int(2e18));
    }
    int all=cntofdif;
    vector<pii>ranges;
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        if(all<=r-l+1){
            cout<<all;
            return 0;
        }
        l%=all;
        r%=all;
        if(l<=r){
            ranges.pb({l,r});
            //cerr<<"inserted "<<l<<" "<<r<<"\n";
        }
        else{
            //cerr<<"oops "<<l<<" "<<r<<"\n";
            ranges.pb({l,all-1});
            ranges.pb({0,r});
        }
    }
    sort(ranges.begin(),ranges.end());
    int cnt=0,left=-1;
    for(auto[f,s]:ranges){
        if(left<f){
            cnt+=s-f+1;
        }else{
            cnt+=s-left;
        }
        left=max(left,s);
    }
    cout<<cnt<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 233 ms 18624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 233 ms 18624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 233 ms 18624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 28 ms 2564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 736 KB Output isn't correct
3 Halted 0 ms 0 KB -