# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213053 | 2020-03-24T19:52:17 Z | arman_ferdous | 이상한 기계 (APIO19_strange_device) | C++17 | 589 ms | 53316 KB |
/* at time = 0, (x, y) = (0, 0) * we need to find minimum t > 0, such that (x, y) = 0 again ie. the cycle period. * now, y = 0 = t % B => t = K * B (for some integer K) * putting t in x's eqn and simplifying gives us a nice formula * K * (B + 1) % A = 0 * from here it is easy to find K's value. * answering queries are just merging intervals */ #include <bits/stdc++.h> using namespace std; using ll = long long; const double oo = 1e19; vector<pair<ll,ll>> interval; int main () { int n; ll A, B; scanf("%d %lld %lld", &n, &A, &B); int inf = 0; ll sum = 0; ll g = __gcd(A, B + 1); ll K = A / g; ll T = K * B; if(K * 1.0 > oo / B * 1.0) inf = 1; while(n--) { ll l, r; scanf("%lld %lld", &l, &r); if(!inf && r - l + 1 >= T) { printf("%lld\n", T); return 0; } sum += r - l + 1; ll le = l % T; ll ri = r % T; if(le <= ri) { interval.push_back({le, ri}); } else { interval.push_back({0, ri}); interval.push_back({le, T - 1}); } } if(inf) printf("%lld\n", sum); else { ll ans = 0, ptr = -1; sort(interval.begin(), interval.end()); for(int i = 0; i < (int)interval.size(); i++) { if(ptr < interval[i].first) { ans += interval[i].second - interval[i].first + 1; ptr = interval[i].second; } else { ans += max(0ll, interval[i].second - ptr); ptr = max(ptr, interval[i].second); } } printf("%lld\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
3 | Correct | 10 ms | 768 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 512 KB | Output is correct |
16 | Correct | 10 ms | 768 KB | Output is correct |
17 | Correct | 60 ms | 2548 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 6 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 412 ms | 16852 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 519 ms | 16848 KB | Output is correct |
3 | Correct | 498 ms | 16848 KB | Output is correct |
4 | Correct | 499 ms | 16852 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 519 ms | 16848 KB | Output is correct |
3 | Correct | 498 ms | 16848 KB | Output is correct |
4 | Correct | 499 ms | 16852 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 507 ms | 16848 KB | Output is correct |
7 | Correct | 521 ms | 16848 KB | Output is correct |
8 | Correct | 506 ms | 16956 KB | Output is correct |
9 | Correct | 551 ms | 16848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 519 ms | 16848 KB | Output is correct |
3 | Correct | 498 ms | 16848 KB | Output is correct |
4 | Correct | 499 ms | 16852 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 56 ms | 2668 KB | Output is correct |
7 | Correct | 59 ms | 2540 KB | Output is correct |
8 | Correct | 52 ms | 2540 KB | Output is correct |
9 | Correct | 55 ms | 2540 KB | Output is correct |
10 | Correct | 56 ms | 2540 KB | Output is correct |
11 | Correct | 57 ms | 2540 KB | Output is correct |
12 | Correct | 55 ms | 2536 KB | Output is correct |
13 | Correct | 58 ms | 2540 KB | Output is correct |
14 | Correct | 55 ms | 2540 KB | Output is correct |
15 | Correct | 60 ms | 2540 KB | Output is correct |
16 | Correct | 59 ms | 5736 KB | Output is correct |
17 | Correct | 66 ms | 5736 KB | Output is correct |
18 | Correct | 550 ms | 53308 KB | Output is correct |
19 | Correct | 506 ms | 53316 KB | Output is correct |
20 | Correct | 576 ms | 53308 KB | Output is correct |
21 | Correct | 58 ms | 5740 KB | Output is correct |
22 | Correct | 54 ms | 5736 KB | Output is correct |
23 | Correct | 195 ms | 18524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 58 ms | 2548 KB | Output is correct |
3 | Correct | 58 ms | 2536 KB | Output is correct |
4 | Correct | 583 ms | 16852 KB | Output is correct |
5 | Correct | 57 ms | 2540 KB | Output is correct |
6 | Correct | 56 ms | 2540 KB | Output is correct |
7 | Correct | 56 ms | 2540 KB | Output is correct |
8 | Correct | 58 ms | 2540 KB | Output is correct |
9 | Correct | 57 ms | 2540 KB | Output is correct |
10 | Correct | 57 ms | 2548 KB | Output is correct |
11 | Correct | 60 ms | 2540 KB | Output is correct |
12 | Correct | 51 ms | 2540 KB | Output is correct |
13 | Correct | 57 ms | 2540 KB | Output is correct |
14 | Correct | 565 ms | 16848 KB | Output is correct |
15 | Correct | 61 ms | 5736 KB | Output is correct |
16 | Correct | 531 ms | 53308 KB | Output is correct |
17 | Correct | 529 ms | 53308 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
3 | Correct | 10 ms | 768 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 512 KB | Output is correct |
16 | Correct | 10 ms | 768 KB | Output is correct |
17 | Correct | 60 ms | 2548 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 6 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 512 KB | Output is correct |
28 | Correct | 412 ms | 16852 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 519 ms | 16848 KB | Output is correct |
31 | Correct | 498 ms | 16848 KB | Output is correct |
32 | Correct | 499 ms | 16852 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 507 ms | 16848 KB | Output is correct |
35 | Correct | 521 ms | 16848 KB | Output is correct |
36 | Correct | 506 ms | 16956 KB | Output is correct |
37 | Correct | 551 ms | 16848 KB | Output is correct |
38 | Correct | 5 ms | 384 KB | Output is correct |
39 | Correct | 56 ms | 2668 KB | Output is correct |
40 | Correct | 59 ms | 2540 KB | Output is correct |
41 | Correct | 52 ms | 2540 KB | Output is correct |
42 | Correct | 55 ms | 2540 KB | Output is correct |
43 | Correct | 56 ms | 2540 KB | Output is correct |
44 | Correct | 57 ms | 2540 KB | Output is correct |
45 | Correct | 55 ms | 2536 KB | Output is correct |
46 | Correct | 58 ms | 2540 KB | Output is correct |
47 | Correct | 55 ms | 2540 KB | Output is correct |
48 | Correct | 60 ms | 2540 KB | Output is correct |
49 | Correct | 59 ms | 5736 KB | Output is correct |
50 | Correct | 66 ms | 5736 KB | Output is correct |
51 | Correct | 550 ms | 53308 KB | Output is correct |
52 | Correct | 506 ms | 53316 KB | Output is correct |
53 | Correct | 576 ms | 53308 KB | Output is correct |
54 | Correct | 58 ms | 5740 KB | Output is correct |
55 | Correct | 54 ms | 5736 KB | Output is correct |
56 | Correct | 195 ms | 18524 KB | Output is correct |
57 | Correct | 5 ms | 384 KB | Output is correct |
58 | Correct | 58 ms | 2548 KB | Output is correct |
59 | Correct | 58 ms | 2536 KB | Output is correct |
60 | Correct | 583 ms | 16852 KB | Output is correct |
61 | Correct | 57 ms | 2540 KB | Output is correct |
62 | Correct | 56 ms | 2540 KB | Output is correct |
63 | Correct | 56 ms | 2540 KB | Output is correct |
64 | Correct | 58 ms | 2540 KB | Output is correct |
65 | Correct | 57 ms | 2540 KB | Output is correct |
66 | Correct | 57 ms | 2548 KB | Output is correct |
67 | Correct | 60 ms | 2540 KB | Output is correct |
68 | Correct | 51 ms | 2540 KB | Output is correct |
69 | Correct | 57 ms | 2540 KB | Output is correct |
70 | Correct | 565 ms | 16848 KB | Output is correct |
71 | Correct | 61 ms | 5736 KB | Output is correct |
72 | Correct | 531 ms | 53308 KB | Output is correct |
73 | Correct | 529 ms | 53308 KB | Output is correct |
74 | Correct | 5 ms | 384 KB | Output is correct |
75 | Correct | 5 ms | 384 KB | Output is correct |
76 | Correct | 5 ms | 384 KB | Output is correct |
77 | Correct | 5 ms | 384 KB | Output is correct |
78 | Correct | 5 ms | 384 KB | Output is correct |
79 | Correct | 10 ms | 1152 KB | Output is correct |
80 | Correct | 579 ms | 53308 KB | Output is correct |
81 | Correct | 589 ms | 53308 KB | Output is correct |
82 | Correct | 545 ms | 53308 KB | Output is correct |
83 | Correct | 545 ms | 53312 KB | Output is correct |
84 | Correct | 583 ms | 53308 KB | Output is correct |
85 | Correct | 552 ms | 53308 KB | Output is correct |
86 | Correct | 199 ms | 18524 KB | Output is correct |
87 | Correct | 5 ms | 384 KB | Output is correct |