# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238389 | 2020-06-11T00:25:24 Z | luciocf | Strange Device (APIO19_strange_device) | C++14 | 820 ms | 33596 KB |
// APIO 2019 - Strange Device // Lúcio Cardoso #include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<ll, int> pii; const int maxn = 3e6+10; const ll inf = 1e18; int n; ll A, B, p; vector<pii> event; void add_event(ll l, ll r) { if (p <= inf/B) l %= (p*B), r %= (p*B); if (l <= r) { event.push_back({l, 0}); event.push_back({r, 1}); } else { event.push_back({l, 0}); event.push_back({p*B-1ll, 1}); event.push_back({0, 0}); event.push_back({r, 1}); } } int main(void) { scanf("%d %lld %lld", &n, &A, &B); ll g = __gcd(A, B+1); p = A/g; bool flag = 0; for (int i = 1; i <= n; i++) { ll l, r; scanf("%lld %lld", &l, &r); if ((r-l+1)/p >= B) flag = 1; add_event(l, r); } if (flag) { printf("%lld\n", p*B); return 0; } ll prev, ans = 0; int open = 0; sort(event.begin(), event.end()); for (auto E: event) { ll x = E.ff, type = E.ss; if (open == 0) prev = x; if (type == 0) open++; else open--; if (open == 0) ans += (x-prev+1ll); } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 11 ms | 1276 KB | Output is correct |
3 | Correct | 11 ms | 1276 KB | Output is correct |
4 | Correct | 4 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 4 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 4 ms | 256 KB | Output is correct |
9 | Correct | 5 ms | 256 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 256 KB | Output is correct |
12 | Correct | 4 ms | 256 KB | Output is correct |
13 | Correct | 4 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 12 ms | 1276 KB | Output is correct |
17 | Correct | 77 ms | 4844 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 6 ms | 384 KB | Output is correct |
5 | Correct | 510 ms | 33340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 649 ms | 33332 KB | Output is correct |
3 | Correct | 671 ms | 33340 KB | Output is correct |
4 | Correct | 639 ms | 33368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 649 ms | 33332 KB | Output is correct |
3 | Correct | 671 ms | 33340 KB | Output is correct |
4 | Correct | 639 ms | 33368 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 666 ms | 33596 KB | Output is correct |
7 | Correct | 669 ms | 33340 KB | Output is correct |
8 | Correct | 649 ms | 33340 KB | Output is correct |
9 | Correct | 791 ms | 33340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 649 ms | 33332 KB | Output is correct |
3 | Correct | 671 ms | 33340 KB | Output is correct |
4 | Correct | 639 ms | 33368 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 69 ms | 4976 KB | Output is correct |
7 | Correct | 70 ms | 4964 KB | Output is correct |
8 | Correct | 63 ms | 4968 KB | Output is correct |
9 | Correct | 68 ms | 4968 KB | Output is correct |
10 | Correct | 67 ms | 4968 KB | Output is correct |
11 | Correct | 71 ms | 4976 KB | Output is correct |
12 | Correct | 65 ms | 4976 KB | Output is correct |
13 | Correct | 75 ms | 4968 KB | Output is correct |
14 | Correct | 67 ms | 4968 KB | Output is correct |
15 | Correct | 76 ms | 4968 KB | Output is correct |
16 | Correct | 72 ms | 4964 KB | Output is correct |
17 | Correct | 67 ms | 4968 KB | Output is correct |
18 | Correct | 676 ms | 33340 KB | Output is correct |
19 | Correct | 626 ms | 33468 KB | Output is correct |
20 | Correct | 758 ms | 33340 KB | Output is correct |
21 | Correct | 77 ms | 4968 KB | Output is correct |
22 | Correct | 60 ms | 4968 KB | Output is correct |
23 | Correct | 225 ms | 17316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 73 ms | 4964 KB | Output is correct |
3 | Correct | 75 ms | 4840 KB | Output is correct |
4 | Correct | 820 ms | 33412 KB | Output is correct |
5 | Correct | 78 ms | 4968 KB | Output is correct |
6 | Correct | 71 ms | 4964 KB | Output is correct |
7 | Correct | 72 ms | 4964 KB | Output is correct |
8 | Correct | 77 ms | 5096 KB | Output is correct |
9 | Correct | 69 ms | 4968 KB | Output is correct |
10 | Correct | 75 ms | 4968 KB | Output is correct |
11 | Correct | 75 ms | 4968 KB | Output is correct |
12 | Correct | 65 ms | 4968 KB | Output is correct |
13 | Correct | 75 ms | 4968 KB | Output is correct |
14 | Correct | 808 ms | 33352 KB | Output is correct |
15 | Correct | 77 ms | 4968 KB | Output is correct |
16 | Correct | 630 ms | 33340 KB | Output is correct |
17 | Correct | 675 ms | 33340 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 11 ms | 1276 KB | Output is correct |
3 | Correct | 11 ms | 1276 KB | Output is correct |
4 | Correct | 4 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 256 KB | Output is correct |
6 | Correct | 4 ms | 256 KB | Output is correct |
7 | Correct | 5 ms | 256 KB | Output is correct |
8 | Correct | 4 ms | 256 KB | Output is correct |
9 | Correct | 5 ms | 256 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 256 KB | Output is correct |
12 | Correct | 4 ms | 256 KB | Output is correct |
13 | Correct | 4 ms | 256 KB | Output is correct |
14 | Correct | 5 ms | 256 KB | Output is correct |
15 | Correct | 5 ms | 256 KB | Output is correct |
16 | Correct | 12 ms | 1276 KB | Output is correct |
17 | Correct | 77 ms | 4844 KB | Output is correct |
18 | Correct | 5 ms | 256 KB | Output is correct |
19 | Correct | 5 ms | 256 KB | Output is correct |
20 | Correct | 4 ms | 256 KB | Output is correct |
21 | Correct | 5 ms | 256 KB | Output is correct |
22 | Correct | 5 ms | 256 KB | Output is correct |
23 | Correct | 5 ms | 256 KB | Output is correct |
24 | Correct | 5 ms | 256 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 6 ms | 384 KB | Output is correct |
27 | Correct | 6 ms | 384 KB | Output is correct |
28 | Correct | 510 ms | 33340 KB | Output is correct |
29 | Correct | 5 ms | 256 KB | Output is correct |
30 | Correct | 649 ms | 33332 KB | Output is correct |
31 | Correct | 671 ms | 33340 KB | Output is correct |
32 | Correct | 639 ms | 33368 KB | Output is correct |
33 | Correct | 4 ms | 256 KB | Output is correct |
34 | Correct | 666 ms | 33596 KB | Output is correct |
35 | Correct | 669 ms | 33340 KB | Output is correct |
36 | Correct | 649 ms | 33340 KB | Output is correct |
37 | Correct | 791 ms | 33340 KB | Output is correct |
38 | Correct | 4 ms | 256 KB | Output is correct |
39 | Correct | 69 ms | 4976 KB | Output is correct |
40 | Correct | 70 ms | 4964 KB | Output is correct |
41 | Correct | 63 ms | 4968 KB | Output is correct |
42 | Correct | 68 ms | 4968 KB | Output is correct |
43 | Correct | 67 ms | 4968 KB | Output is correct |
44 | Correct | 71 ms | 4976 KB | Output is correct |
45 | Correct | 65 ms | 4976 KB | Output is correct |
46 | Correct | 75 ms | 4968 KB | Output is correct |
47 | Correct | 67 ms | 4968 KB | Output is correct |
48 | Correct | 76 ms | 4968 KB | Output is correct |
49 | Correct | 72 ms | 4964 KB | Output is correct |
50 | Correct | 67 ms | 4968 KB | Output is correct |
51 | Correct | 676 ms | 33340 KB | Output is correct |
52 | Correct | 626 ms | 33468 KB | Output is correct |
53 | Correct | 758 ms | 33340 KB | Output is correct |
54 | Correct | 77 ms | 4968 KB | Output is correct |
55 | Correct | 60 ms | 4968 KB | Output is correct |
56 | Correct | 225 ms | 17316 KB | Output is correct |
57 | Correct | 5 ms | 256 KB | Output is correct |
58 | Correct | 73 ms | 4964 KB | Output is correct |
59 | Correct | 75 ms | 4840 KB | Output is correct |
60 | Correct | 820 ms | 33412 KB | Output is correct |
61 | Correct | 78 ms | 4968 KB | Output is correct |
62 | Correct | 71 ms | 4964 KB | Output is correct |
63 | Correct | 72 ms | 4964 KB | Output is correct |
64 | Correct | 77 ms | 5096 KB | Output is correct |
65 | Correct | 69 ms | 4968 KB | Output is correct |
66 | Correct | 75 ms | 4968 KB | Output is correct |
67 | Correct | 75 ms | 4968 KB | Output is correct |
68 | Correct | 65 ms | 4968 KB | Output is correct |
69 | Correct | 75 ms | 4968 KB | Output is correct |
70 | Correct | 808 ms | 33352 KB | Output is correct |
71 | Correct | 77 ms | 4968 KB | Output is correct |
72 | Correct | 630 ms | 33340 KB | Output is correct |
73 | Correct | 675 ms | 33340 KB | Output is correct |
74 | Correct | 5 ms | 256 KB | Output is correct |
75 | Correct | 5 ms | 256 KB | Output is correct |
76 | Correct | 5 ms | 384 KB | Output is correct |
77 | Correct | 4 ms | 384 KB | Output is correct |
78 | Correct | 5 ms | 256 KB | Output is correct |
79 | Correct | 10 ms | 1404 KB | Output is correct |
80 | Correct | 772 ms | 33332 KB | Output is correct |
81 | Correct | 773 ms | 33292 KB | Output is correct |
82 | Correct | 727 ms | 33468 KB | Output is correct |
83 | Correct | 723 ms | 33532 KB | Output is correct |
84 | Correct | 722 ms | 33356 KB | Output is correct |
85 | Correct | 729 ms | 33340 KB | Output is correct |
86 | Correct | 223 ms | 16976 KB | Output is correct |
87 | Correct | 5 ms | 256 KB | Output is correct |