# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1105463 | borisAngelov | 이상한 기계 (APIO19_strange_device) | C++17 | 292 ms | 19020 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long MAXMOD = 1e18 + 7;
int n;
long long a, b;
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> a >> b;
long long MOD = a / __gcd(a, b + 1);
bool hasPeriod = true;
if (MAXMOD / MOD < b)
{
hasPeriod = false;
}
else
{
MOD *= b; // a * b / gcd(a, b + 1)
}
vector<pair<long long, long long>> intervals;
long long ans = 0;
for (int i = 1; i <= n; ++i)
{
long long l, r;
cin >> l >> r;
if (hasPeriod == false)
{
ans += (r - l + 1);
}
else
{
long long newL = l % MOD;
long long newR = r % MOD;
if (newL < newR || (newL == newR && l == r))
{
intervals.push_back({newL, newR});
}
else
{
intervals.push_back({newL, MOD - 1});
intervals.push_back({0, newR});
}
}
}
if (hasPeriod == false)
{
cout << 1/0 << endl;
cout << ans << endl;
return 0;
}
sort(intervals.begin(), intervals.end());
long long from = intervals[0].first, to = intervals[0].second;
for (int i = 1; i < intervals.size(); ++i)
{
if (intervals[i].first <= to)
{
to = intervals[i].second;
}
else
{
ans += (to - from + 1);
from = intervals[i].first;
to = intervals[i].second;
}
}
ans += (to - from + 1);
cout << ans << endl;
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... |