# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252084 | jeqcho | Strange Device (APIO19_strange_device) | C++17 | 616 ms | 16120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
int n,tot=0;
LL A,B,len,ans=0;
struct node{LL l,r;} a[2000010];
LL gcd(LL x,LL y)
{
return !y?x:gcd(y,x%y);
}
bool cmp(node x,node y)
{
return x.l==y.l?x.r<y.r:x.l<y.l;
}
int main()
{
LL l,r;
scanf("%d %lld %lld",&n,&A,&B);
len=(A*B/gcd(A,B+1));
for(int i=1;i<=n;i++)
{
scanf("%lld %lld",&l,&r);
if(r-l+1>=len)
{
printf("%lld\n",len);
return 0;
}
if(l%len<=r%len) a[++tot]=(node){l%len,r%len}; else a[++tot]=(node){l%len,len-1},a[++tot]=(node){0,r%len};
}
sort(a+1,a+tot+1,cmp);
l=a[1].l,r=a[1].r;
for(int i=2;i<=tot;i++)
{
if(a[i].l>r) {ans+=r-l+1;l=a[i].l,r=a[i].r;continue;}
r=max(r,a[i].r);
}
ans+=r-l+1;
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |