# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
252084 | jeqcho | 이상한 기계 (APIO19_strange_device) | C++17 | 616 ms | 16120 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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... |