Submission #744204

# Submission time Handle Problem Language Result Execution time Memory
744204 2023-05-18T09:16:05 Z iamporrrrrrrrr Strange Device (APIO19_strange_device) C++14
0 / 100
489 ms 34588 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
set<int> s;
vector<pair<int,int>> v;
int g(int a,int b){
    if(b==0) return a;
    return g(b,a%b);
}
int st[1000010],ed[1000010];
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,a,b;
    int sum=0;
    cin>>n>>a>>b;
    int dmod = g(max(a,b+1),min(a,b+1));
    for(int i=1;i<=n;i++){
        cin>>st[i]>>ed[i];
        sum+=ed[i]-st[i]+1;
    }
    if((double)ed[n]/(a/dmod)<=(double)b){
        cout<<sum;
        return 0;
    }
    int mod=a/dmod*b;
    for(int i=1;i<=n;i++){
        int y=st[i];
        int x=ed[i];
        if(y-x>mod){
            cout<<mod;
            return 0;
        }
        x%=mod;
        y%=mod;
        if(y>=x){
            v.push_back({x,y});
        }
        else v.push_back({x,mod-1}),v.push_back({0,y});
    }
    sort(v.begin(),v.end());
    int rr=-1,ans=0;
    for(int i=0;i<v.size();i++){
        int l=v[i].first;
        int r=v[i].second;
        if(l>rr){
            ans+=(r-l+1);
            rr=r;
        }
        else if(l<=rr&&r>rr){
            ans+=(r-rr);
            rr=r;
        }
    }
    cout<<ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:43:18: 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]
   43 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 6 ms 1480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 489 ms 34588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 489 ms 34588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 489 ms 34588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Incorrect 49 ms 9860 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 6 ms 1480 KB Output isn't correct
3 Halted 0 ms 0 KB -