# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
347843 | denkendoemeer | 이상한 기계 (APIO19_strange_device) | C++14 | 585 ms | 36704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll,ll>>v;
ll gcd(ll a,ll b)
{
ll r=0;
while(b){
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ll n,a,b,g,i,x,y,ans=0;
scanf("%lld%lld%lld",&n,&a,&b);
g=gcd(a,b+1);
if ((long double)a/g*b>1e18){
for(i=1;i<=n;i++)
scanf("%lld%lld",&x,&y),ans=ans+y-x+1;
printf("%lld\n",ans);
return 0;
}
ll aux=a/g*b;
for(i=1;i<=n;i++){
scanf("%lld%lld",&x,&y);
if (y-x+1>=aux){
printf("%lld\n",aux);
return 0;
}
x=x%aux;
y=y%aux;
if (x>y){
v.push_back(make_pair(x,aux-1));
v.push_back(make_pair(0,y));
}
else
v.push_back(make_pair(x,y));
}
sort(v.begin(),v.end());
ll last=-1;
for(auto it:v){
ans=ans+max(0LL,it.second-max(last,it.first-1));
last=max(last,it.second);
}
printf("%lld\n",min(ans,aux));
return 0;
}
컴파일 시 표준 에러 (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... |