# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
764729 | KN200711 | 이상한 기계 (APIO19_strange_device) | C++14 | 392 ms | 53348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
int main() {
int N;
ll A, B;
scanf("%d %lld %lld", &N, &A, &B);
ll P = A / __gcd(A, B + 1ll);
vector< pair<ll, ll> > ln;
ln.clear();
ll BC = 0ll;
bool cek = 1;
if(1e18 / B >= P) BC = B * P;
else cek = 0;
// cout<<cek<<" "<<BC<<endl;
ll ans = 0ll;
for(int i=0;i<N;i++) {
ll L, R;
scanf("%lld %lld", &L, &R);
if(cek && (R - L + 1) >= BC) {
printf("%lld\n", BC);
return 0;
}
if(!cek) ans += R - L + 1ll;
else {
if(L%BC <= R%BC) {
ln.push_back(make_pair(L%BC, R%BC));
} else {
ln.push_back(make_pair(L%BC, BC - 1));
ln.push_back(make_pair(0, R%BC));
}
}
}
if(!cek) printf("%lld\n", ans);
else {
sort(ln.begin(), ln.end());
ll nw = -1ll, as = 0ll;
for(auto p : ln) {
// cout<<p.fi<<" "<<p.se<<endl;
if(nw < p.fi) {
as += p.se - p.fi + 1ll;
} else if(nw < p.se) {
as += p.se - nw;
}
nw = max(nw, p.se);
}
printf("%lld\n", as);
return 0;
}
}
Compilation message (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... |