이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, a, b;
bool overflow(int x, int y) {
int result = x * y;
return result / x != y;
}
int sum() {
int ans = 0;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
ans += r - l + 1;
}
return ans;
}
int solveTestCase() {
cin >> n >> a >> b;
int temp = a / __gcd(a, b + 1);
assert(a % __gcd(a, b + 1) == 0);
if (overflow(temp, b))
return cout << sum(), 0;
temp *= b;
//cerr << temp << "\n";
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= temp)
return cout << temp, 0;
if (l % temp <= r % temp)
v.emplace_back(l % temp, 1), v.emplace_back(r % temp + 1, 2);
else
v.emplace_back(l % temp, 1), v.emplace_back(temp, 2), v.emplace_back(0, 1), v.emplace_back(r % temp + 1, 2), assert(l % temp > r % temp + 1);
}
sort(v.begin(), v.end());
int ans = 0, d = 0, last = 0;
for (auto i : v) {
if (d == 0)
last = i.first;
if (i.second == 1)
d++;
else
d--;
assert(d >= 0);
if (d == 0)
ans += i.first - last;
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--)
solveTestCase();
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'long long int solveTestCase()':
strange_device.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |