# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
496123 | aryan12 | Strange Device (APIO19_strange_device) | C++17 | 547 ms | 69884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int MAXT = 1e18 + 5;
int gcd(int a, int b) {
if(a % b == 0) {
return b;
}
return gcd(b, a % b);
}
void Solve() {
int n, a, b;
cin >> n >> a >> b;
int repetition = a / gcd(a, b + 1);
vector<pair<int, int> > v(n + 1);
int sum = 0;
for(int i = 1; i <= n; i++) {
cin >> v[i].first >> v[i].second;
sum += (v[i].second - v[i].first + 1);
}
if(b > MAXT / repetition) {
cout << sum << "\n";
return;
}
int repetition2 = a / gcd(a, b + 1) * b;
vector<pair<int, int> > temp;
for(int i = 1; i <= n; i++) {
if(v[i].second - v[i].first + 1 >= repetition2) {
cout << repetition2 << "\n";
return;
}
int startpoint = v[i].first % repetition2;
int endpoint = v[i].second % repetition2;
if(startpoint <= endpoint) {
temp.push_back({startpoint, endpoint});
}
else {
temp.push_back({startpoint, repetition2 - 1});
temp.push_back({0LL, endpoint});
}
}
sort(temp.begin(), temp.end());
int ans = 0, left = 0, right = -1;
for(int i = 0; i < temp.size(); i++) {
if(temp[i].first > right) {
ans += (right - left + 1);
left = temp[i].first;
right = temp[i].second;
}
else {
right = max(right, temp[i].second);
}
}
ans += (right - left + 1);
cout << ans << "\n";
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\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... |