# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171729 | Sensei | 이상한 기계 (APIO19_strange_device) | C++17 | 660 ms | 46388 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
DATE: 2019-12-30 11:10:15
NAME:
PROBLEM: APIO19_strange_device
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const long long LLINF = 1e18 + 100;
class Segment {
public:
long long l, r;
Segment() {}
Segment(long long x, long long y) {
l = x;
r = y;
}
};
long long f(long long x, long long y) {
if (x / __gcd(x, y) > LLINF / y) {
return LLINF;
}
return x * y;
}
int main() {
int n;
cin >> n;
long long A, B;
cin >> A >> B;
long long C = f(A, B);
vector<Segment> segments;
for (int i = 1; i <= n; i++) {
Segment segment;
scanf("%lld %lld", &segment.l, &segment.r);
segment.l %= C;
segment.r %= C;
if (segment.l <= segment.r) {
segments.push_back(segment);
}
else {
segments.push_back(Segment(0, segment.r));
segments.push_back(Segment(segment.l, C - 1));
}
}
sort(segments.begin(), segments.end(), [](Segment x, Segment y) {
if (x.l == y.l) {
return x.r < y.r;
}
return x.l < y.l;
});
long long lastr = -1;
long long ans = 0;
for (int i = 0; i < segments.size(); i++) {
if (segments[i].l > lastr) {
lastr = segments[i].l - 1;
}
if (segments[i].r > lastr) {
ans += segments[i].r - lastr;
lastr = segments[i].r;
}
}
cout << ans << "\n";
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... |