# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261513 | Kastanda | Strange Device (APIO19_strange_device) | C++11 | 657 ms | 41276 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 pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
int n;
ll A, B, K;
int main()
{
scanf("%d%lld%lld", &n, &A, &B);
ll K = A / __gcd(A, B + 1);
if ((long double)K * B < 2e18)
K *= B;
else
K = (ll)(2e18);
vector < pii > vec;
for (int i = 0; i < n; i ++)
{
ll l, r;
scanf("%lld%lld", &l, &r);
if (r - l + 1 >= K)
return !printf("%lld\n", K);
if (l % K <= r % K)
vec.pb(pii(l % K, r % K));
else
vec.pb(pii(l % K, K - 1)), vec.pb(pii(0, r % K));
}
sort(vec.begin(), vec.end());
ll tot = 0, r = -1;
for (pii X : vec)
{
X.y ++;
if (r >= X.y)
continue;
if (r < X.x)
r = X.x;
tot += X.y - r;
r = X.y;
}
return !printf("%lld\n", tot);
}
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... |