# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361917 | parsabahrami | Strange Device (APIO19_strange_device) | C++17 | 780 ms | 81388 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.
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 1e6 + 10;
ll A, B; int n; set<pii> st;
int main() {
scanf("%d%lld%lld", &n, &A, &B);
ll blk = A / __gcd(A, B + 1) * B;
for (int i = 1; i <= n; i++) {
ll l, r; scanf("%lld%lld", &l, &r);
if (r - l + 1 >= blk) return !printf("%lld\n", blk);
if (l % blk <= r % blk) st.insert({l % blk, -(r % blk)});
else st.insert({0, -(r % blk)}), st.insert({l % blk, -(blk - 1)});
}
ll mx = -1, ret = 0;
for (pii x : st) {
ret += max(0ll, -x.S - max(mx + 1, x.F) + 1);
mx = max(mx, -x.S);
}
printf("%lld\n", ret);
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... |