# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527463 | 2022-02-17T12:58:41 Z | LucaDantas | Strange Device (APIO19_strange_device) | C++17 | 526 ms | 23732 KB |
#include <bits/stdc++.h> using namespace std; constexpr long long inf = 0x3f3f3f3f3f3f3f3f; int main() { long long n, A, B; scanf("%lld %lld %lld", &n, &A, &B); long long g = __gcd(A, B+1), sz = 0; if(log(A) + log(B) - log(g) > log(inf)) sz = inf; else sz = (A/g) * B; vector<pair<long long, long long>> pares; long long ini = 0, fim = -1, ans = 0; for(int i = 0; i < n; i++) { long long l, r; scanf("%lld %lld", &l, &r); if(r - l + 1 >= sz) return printf("%lld\n", sz), 0; l %= sz, r %= sz; if(r < l) fim = max(fim, r), pares.push_back({l, sz-1}); else pares.push_back({l, r}); } sort(pares.begin(), pares.end()); for(auto p : pares) { if(p.first > fim) ans += fim - ini+1, ini = p.first, fim = p.second; else fim = max(fim, p.second); } printf("%lld\n", ans + fim - ini + 1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 5 ms | 1000 KB | Output is correct |
3 | Correct | 5 ms | 964 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 288 KB | Output is correct |
9 | Correct | 1 ms | 288 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 288 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 5 ms | 1036 KB | Output is correct |
17 | Correct | 50 ms | 5624 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 341 ms | 17964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 488 ms | 20020 KB | Output is correct |
3 | Correct | 471 ms | 19972 KB | Output is correct |
4 | Correct | 429 ms | 20668 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 488 ms | 20020 KB | Output is correct |
3 | Correct | 471 ms | 19972 KB | Output is correct |
4 | Correct | 429 ms | 20668 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 485 ms | 20516 KB | Output is correct |
7 | Correct | 451 ms | 20272 KB | Output is correct |
8 | Correct | 453 ms | 20308 KB | Output is correct |
9 | Correct | 480 ms | 19976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 488 ms | 20020 KB | Output is correct |
3 | Correct | 471 ms | 19972 KB | Output is correct |
4 | Correct | 429 ms | 20668 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 43 ms | 5668 KB | Output is correct |
7 | Correct | 45 ms | 5564 KB | Output is correct |
8 | Correct | 44 ms | 5580 KB | Output is correct |
9 | Correct | 48 ms | 5680 KB | Output is correct |
10 | Correct | 44 ms | 5680 KB | Output is correct |
11 | Correct | 45 ms | 5636 KB | Output is correct |
12 | Correct | 50 ms | 5652 KB | Output is correct |
13 | Correct | 54 ms | 5604 KB | Output is correct |
14 | Correct | 44 ms | 5640 KB | Output is correct |
15 | Correct | 49 ms | 5576 KB | Output is correct |
16 | Correct | 50 ms | 5596 KB | Output is correct |
17 | Correct | 46 ms | 5584 KB | Output is correct |
18 | Correct | 431 ms | 22448 KB | Output is correct |
19 | Correct | 418 ms | 22596 KB | Output is correct |
20 | Correct | 475 ms | 22520 KB | Output is correct |
21 | Correct | 53 ms | 5680 KB | Output is correct |
22 | Correct | 48 ms | 5592 KB | Output is correct |
23 | Correct | 153 ms | 18484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 47 ms | 5672 KB | Output is correct |
3 | Correct | 46 ms | 5652 KB | Output is correct |
4 | Correct | 506 ms | 19984 KB | Output is correct |
5 | Correct | 46 ms | 5640 KB | Output is correct |
6 | Correct | 52 ms | 5616 KB | Output is correct |
7 | Correct | 51 ms | 5680 KB | Output is correct |
8 | Correct | 48 ms | 5752 KB | Output is correct |
9 | Correct | 48 ms | 5568 KB | Output is correct |
10 | Correct | 62 ms | 5684 KB | Output is correct |
11 | Correct | 49 ms | 5652 KB | Output is correct |
12 | Correct | 44 ms | 5680 KB | Output is correct |
13 | Correct | 48 ms | 5680 KB | Output is correct |
14 | Correct | 453 ms | 20592 KB | Output is correct |
15 | Correct | 47 ms | 5684 KB | Output is correct |
16 | Correct | 481 ms | 21784 KB | Output is correct |
17 | Correct | 450 ms | 22468 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 5 ms | 1000 KB | Output is correct |
3 | Correct | 5 ms | 964 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 288 KB | Output is correct |
9 | Correct | 1 ms | 288 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 288 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 5 ms | 1036 KB | Output is correct |
17 | Correct | 50 ms | 5624 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 1 ms | 288 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 0 ms | 204 KB | Output is correct |
23 | Correct | 0 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 336 KB | Output is correct |
27 | Correct | 1 ms | 308 KB | Output is correct |
28 | Correct | 341 ms | 17964 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 488 ms | 20020 KB | Output is correct |
31 | Correct | 471 ms | 19972 KB | Output is correct |
32 | Correct | 429 ms | 20668 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 485 ms | 20516 KB | Output is correct |
35 | Correct | 451 ms | 20272 KB | Output is correct |
36 | Correct | 453 ms | 20308 KB | Output is correct |
37 | Correct | 480 ms | 19976 KB | Output is correct |
38 | Correct | 0 ms | 204 KB | Output is correct |
39 | Correct | 43 ms | 5668 KB | Output is correct |
40 | Correct | 45 ms | 5564 KB | Output is correct |
41 | Correct | 44 ms | 5580 KB | Output is correct |
42 | Correct | 48 ms | 5680 KB | Output is correct |
43 | Correct | 44 ms | 5680 KB | Output is correct |
44 | Correct | 45 ms | 5636 KB | Output is correct |
45 | Correct | 50 ms | 5652 KB | Output is correct |
46 | Correct | 54 ms | 5604 KB | Output is correct |
47 | Correct | 44 ms | 5640 KB | Output is correct |
48 | Correct | 49 ms | 5576 KB | Output is correct |
49 | Correct | 50 ms | 5596 KB | Output is correct |
50 | Correct | 46 ms | 5584 KB | Output is correct |
51 | Correct | 431 ms | 22448 KB | Output is correct |
52 | Correct | 418 ms | 22596 KB | Output is correct |
53 | Correct | 475 ms | 22520 KB | Output is correct |
54 | Correct | 53 ms | 5680 KB | Output is correct |
55 | Correct | 48 ms | 5592 KB | Output is correct |
56 | Correct | 153 ms | 18484 KB | Output is correct |
57 | Correct | 1 ms | 204 KB | Output is correct |
58 | Correct | 47 ms | 5672 KB | Output is correct |
59 | Correct | 46 ms | 5652 KB | Output is correct |
60 | Correct | 506 ms | 19984 KB | Output is correct |
61 | Correct | 46 ms | 5640 KB | Output is correct |
62 | Correct | 52 ms | 5616 KB | Output is correct |
63 | Correct | 51 ms | 5680 KB | Output is correct |
64 | Correct | 48 ms | 5752 KB | Output is correct |
65 | Correct | 48 ms | 5568 KB | Output is correct |
66 | Correct | 62 ms | 5684 KB | Output is correct |
67 | Correct | 49 ms | 5652 KB | Output is correct |
68 | Correct | 44 ms | 5680 KB | Output is correct |
69 | Correct | 48 ms | 5680 KB | Output is correct |
70 | Correct | 453 ms | 20592 KB | Output is correct |
71 | Correct | 47 ms | 5684 KB | Output is correct |
72 | Correct | 481 ms | 21784 KB | Output is correct |
73 | Correct | 450 ms | 22468 KB | Output is correct |
74 | Correct | 0 ms | 204 KB | Output is correct |
75 | Correct | 0 ms | 296 KB | Output is correct |
76 | Correct | 0 ms | 204 KB | Output is correct |
77 | Correct | 0 ms | 204 KB | Output is correct |
78 | Correct | 0 ms | 288 KB | Output is correct |
79 | Correct | 5 ms | 944 KB | Output is correct |
80 | Correct | 509 ms | 22304 KB | Output is correct |
81 | Correct | 501 ms | 22972 KB | Output is correct |
82 | Correct | 493 ms | 23044 KB | Output is correct |
83 | Correct | 475 ms | 23732 KB | Output is correct |
84 | Correct | 526 ms | 23072 KB | Output is correct |
85 | Correct | 502 ms | 22672 KB | Output is correct |
86 | Correct | 140 ms | 18348 KB | Output is correct |
87 | Correct | 1 ms | 204 KB | Output is correct |