이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;
using ld = long double;
ll const inf = 1000000000000000000;
ll period(ll a, ll b){
ll p = __gcd(a, b + 1);
if(b / p <= inf / a)
return b / p * a;
return inf + 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
ll a, b;
cin >> n >> a >> b;
ll pi = period(a, b);
if(inf < pi){
ll result = 0;
for(int i = 1;i <= n; i++){
ll x, y;
cin >> x >> y;
result += y - x + 1;
}
cout << result;
} else {
vector<pair<ll,int>> event;
for(int i = 1;i <= n; i++){
ll x, y;
cin >> x >> y;
if(y - x < pi){
if(x % pi <= y % pi){
event.push_back({x % pi, 1});
event.push_back({y % pi + 1, -1});
} else {
event.push_back({x % pi, 1});
event.push_back({pi, -1});
event.push_back({0, 1});
event.push_back({y % pi + 1, -1});
}
} else {
cout << pi;
return 0;
}
}
sort(event.begin(), event.end());
ll result = 0, last = 0, sum = 0;
for(int i = 0; i < event.size(); i++){
if(0 < sum)
result += event[i].first - last;
last = event[i].first;
sum += event[i].second;
}
cout << result;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:62:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < event.size(); i++){
~~^~~~~~~~~~~~~~
# | 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... |