# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
126587 | roseanne_pcy | 이상한 기계 (APIO19_strange_device) | C++14 | 911 ms | 49196 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 1e6+5;
ll L[maxn], R[maxn];
vector< pair<ll, int> > sw;
int main()
{
int n;
ll A, B;
scanf("%d %lld %lld", &n, &A, &B);
ll k = A/__gcd(A, B+1);
bool over = false;
if(k*B/B != k) over = true;
ll len = 0;
for(int i = 1; i<= n; i++)
{
scanf("%lld %lld", &L[i], &R[i]);
len += (R[i]-L[i]+1);
}
if(over)
{
printf("%lld\n", len);
return 0;
}
for(int i = 1; i<= n; i++)
{
ll tmp = R[i]-L[i]+1;
if(tmp>= k*B)
{
printf("%lld\n", k*B);
return 0;
}
ll m1 = L[i]%(k*B);
ll m2 = R[i]%(k*B);
if(m1<= m2)
{
sw.pb({m1, 1});
sw.pb({m2+1, -1});
}
else
{
sw.pb({m1, 1});
sw.pb({k*B, -1});
sw.pb({0, 1});
sw.pb({m2+1, -1});
}
}
sort(sw.begin(), sw.end());
ll ans = 0;
int run = 0;
for(int i = 0; i+1< (int) sw.size(); i++)
{
run += sw[i].Y;
if(run> 0)
{
ans += sw[i+1].X-sw[i].X;
}
}
printf("%lld\n", 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... |