# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
221628 | MKopchev | 이상한 기계 (APIO19_strange_device) | C++14 | 1050 ms | 102072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
const long long inf=1e18;
int n;
long long A,B;
pair<long long,long long> inp[nmax];
vector< pair<long long,long long> > segments;
vector< pair<long long,int> > active;
bool cmp(pair<long long,int> s,pair<long long,int> t)
{
if(s.first!=t.first)return s.first<t.first;
return s.second>t.second;
}
int main()
{
scanf("%i%lld%lld",&n,&A,&B);
A=A/__gcd(A,B+1);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&inp[i].first,&inp[i].second);
if(A>inf/B)segments.push_back(inp[i]);
else
{
if(inp[i].second-inp[i].first+1>=A*B)
{
printf("%lld\n",A*B);
return 0;
}
inp[i].first=inp[i].first%(A*B);
inp[i].second=inp[i].second%(A*B);
if(inp[i].first<=inp[i].second)segments.push_back(inp[i]);
else
{
segments.push_back({inp[i].first,A*B-1});
segments.push_back({0,inp[i].second});
}
}
}
for(auto k:segments)
{
active.push_back({k.first,1});
active.push_back({k.second+1,-1});
//cout<<k.first<<" "<<k.second<<endl;
}
sort(active.begin(),active.end(),cmp);
int sum=1;
long long output=0;
for(int i=1;i<active.size();i++)
{
if(sum)output+=active[i].first-active[i-1].first;
sum=sum+active[i].second;
//cout<<i<<" -> "<<sum<<" "<<output<<" "<<active[i].first<<" "<<active[i].second<<endl;
}
printf("%lld\n",output);
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... |