# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531656 | 2022-03-01T08:12:40 Z | 79brue | 이상한 기계 (APIO19_strange_device) | C++14 | 502 ms | 69824 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; ll a, b; ll l[1000002], r[1000002]; int main(){ scanf("%d %lld %lld", &n, &a, &b); for(int i=1; i<=n; i++) scanf("%lld %lld", &l[i], &r[i]); if(1000000000000000000LL / a + 1 <= b){ ll ans = 0; for(int i=1; i<=n; i++) ans += r[i] - l[i] + 1; printf("%lld", ans); return 0; } a = (a/__gcd(a, b+1)) * b; for(int i=1; i<=n; i++){ if(r[i] - l[i] >= a-1){ printf("%lld", a); return 0; } } vector<pair<ll, ll> > vec; for(int i=1; i<=n; i++){ if(l[i]%a <= r[i]%a) vec.push_back(make_pair(l[i]%a, r[i]%a)); else{ vec.push_back(make_pair(0, r[i]%a)); vec.push_back(make_pair(l[i]%a, a-1)); } } sort(vec.begin(), vec.end()); ll ans = 0; ll rMax = vec[0].second; ll lPnt = vec[0].first; for(int i=0; i<(int)vec.size(); i++){ rMax = max(rMax, vec[i].second); if(i<(int)vec.size()-1 && rMax < vec[i+1].first){ ans += rMax - lPnt + 1; lPnt = vec[i+1].first; } else if(i==(int)vec.size()-1){ ans += rMax - lPnt + 1; } else{ rMax = max(rMax, vec[i].second); } } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 7 ms | 1228 KB | Output is correct |
3 | Correct | 6 ms | 1228 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 300 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 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 | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 5 ms | 1208 KB | Output is correct |
17 | Correct | 50 ms | 7740 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 317 ms | 33524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 453 ms | 33908 KB | Output is correct |
3 | Correct | 417 ms | 34572 KB | Output is correct |
4 | Correct | 480 ms | 37672 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 453 ms | 33908 KB | Output is correct |
3 | Correct | 417 ms | 34572 KB | Output is correct |
4 | Correct | 480 ms | 37672 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 446 ms | 37704 KB | Output is correct |
7 | Correct | 439 ms | 37708 KB | Output is correct |
8 | Correct | 427 ms | 37660 KB | Output is correct |
9 | Correct | 494 ms | 69824 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 453 ms | 33908 KB | Output is correct |
3 | Correct | 417 ms | 34572 KB | Output is correct |
4 | Correct | 480 ms | 37672 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 45 ms | 6456 KB | Output is correct |
7 | Correct | 51 ms | 6532 KB | Output is correct |
8 | Correct | 44 ms | 6496 KB | Output is correct |
9 | Correct | 46 ms | 6496 KB | Output is correct |
10 | Correct | 46 ms | 6500 KB | Output is correct |
11 | Correct | 44 ms | 6432 KB | Output is correct |
12 | Correct | 47 ms | 6460 KB | Output is correct |
13 | Correct | 47 ms | 6524 KB | Output is correct |
14 | Correct | 43 ms | 6548 KB | Output is correct |
15 | Correct | 50 ms | 7652 KB | Output is correct |
16 | Correct | 52 ms | 7652 KB | Output is correct |
17 | Correct | 55 ms | 7732 KB | Output is correct |
18 | Correct | 423 ms | 69508 KB | Output is correct |
19 | Correct | 442 ms | 69600 KB | Output is correct |
20 | Correct | 488 ms | 69556 KB | Output is correct |
21 | Correct | 46 ms | 7684 KB | Output is correct |
22 | Correct | 41 ms | 7736 KB | Output is correct |
23 | Correct | 143 ms | 26588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 45 ms | 5200 KB | Output is correct |
3 | Correct | 46 ms | 5120 KB | Output is correct |
4 | Correct | 480 ms | 33976 KB | Output is correct |
5 | Correct | 44 ms | 5176 KB | Output is correct |
6 | Correct | 45 ms | 5160 KB | Output is correct |
7 | Correct | 45 ms | 5144 KB | Output is correct |
8 | Correct | 49 ms | 5176 KB | Output is correct |
9 | Correct | 43 ms | 5228 KB | Output is correct |
10 | Correct | 43 ms | 5152 KB | Output is correct |
11 | Correct | 45 ms | 5144 KB | Output is correct |
12 | Correct | 41 ms | 5188 KB | Output is correct |
13 | Correct | 45 ms | 5144 KB | Output is correct |
14 | Correct | 437 ms | 33912 KB | Output is correct |
15 | Correct | 51 ms | 5136 KB | Output is correct |
16 | Correct | 445 ms | 69560 KB | Output is correct |
17 | Correct | 477 ms | 69688 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 7 ms | 1228 KB | Output is correct |
3 | Correct | 6 ms | 1228 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 300 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 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 | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 5 ms | 1208 KB | Output is correct |
17 | Correct | 50 ms | 7740 KB | Output is correct |
18 | Correct | 0 ms | 300 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 304 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 317 ms | 33524 KB | Output is correct |
29 | Correct | 0 ms | 204 KB | Output is correct |
30 | Correct | 453 ms | 33908 KB | Output is correct |
31 | Correct | 417 ms | 34572 KB | Output is correct |
32 | Correct | 480 ms | 37672 KB | Output is correct |
33 | Correct | 0 ms | 204 KB | Output is correct |
34 | Correct | 446 ms | 37704 KB | Output is correct |
35 | Correct | 439 ms | 37708 KB | Output is correct |
36 | Correct | 427 ms | 37660 KB | Output is correct |
37 | Correct | 494 ms | 69824 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 45 ms | 6456 KB | Output is correct |
40 | Correct | 51 ms | 6532 KB | Output is correct |
41 | Correct | 44 ms | 6496 KB | Output is correct |
42 | Correct | 46 ms | 6496 KB | Output is correct |
43 | Correct | 46 ms | 6500 KB | Output is correct |
44 | Correct | 44 ms | 6432 KB | Output is correct |
45 | Correct | 47 ms | 6460 KB | Output is correct |
46 | Correct | 47 ms | 6524 KB | Output is correct |
47 | Correct | 43 ms | 6548 KB | Output is correct |
48 | Correct | 50 ms | 7652 KB | Output is correct |
49 | Correct | 52 ms | 7652 KB | Output is correct |
50 | Correct | 55 ms | 7732 KB | Output is correct |
51 | Correct | 423 ms | 69508 KB | Output is correct |
52 | Correct | 442 ms | 69600 KB | Output is correct |
53 | Correct | 488 ms | 69556 KB | Output is correct |
54 | Correct | 46 ms | 7684 KB | Output is correct |
55 | Correct | 41 ms | 7736 KB | Output is correct |
56 | Correct | 143 ms | 26588 KB | Output is correct |
57 | Correct | 0 ms | 204 KB | Output is correct |
58 | Correct | 45 ms | 5200 KB | Output is correct |
59 | Correct | 46 ms | 5120 KB | Output is correct |
60 | Correct | 480 ms | 33976 KB | Output is correct |
61 | Correct | 44 ms | 5176 KB | Output is correct |
62 | Correct | 45 ms | 5160 KB | Output is correct |
63 | Correct | 45 ms | 5144 KB | Output is correct |
64 | Correct | 49 ms | 5176 KB | Output is correct |
65 | Correct | 43 ms | 5228 KB | Output is correct |
66 | Correct | 43 ms | 5152 KB | Output is correct |
67 | Correct | 45 ms | 5144 KB | Output is correct |
68 | Correct | 41 ms | 5188 KB | Output is correct |
69 | Correct | 45 ms | 5144 KB | Output is correct |
70 | Correct | 437 ms | 33912 KB | Output is correct |
71 | Correct | 51 ms | 5136 KB | Output is correct |
72 | Correct | 445 ms | 69560 KB | Output is correct |
73 | Correct | 477 ms | 69688 KB | Output is correct |
74 | Correct | 1 ms | 204 KB | Output is correct |
75 | Correct | 1 ms | 304 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 | 296 KB | Output is correct |
79 | Correct | 5 ms | 1212 KB | Output is correct |
80 | Correct | 474 ms | 69632 KB | Output is correct |
81 | Correct | 502 ms | 69584 KB | Output is correct |
82 | Correct | 455 ms | 69548 KB | Output is correct |
83 | Correct | 455 ms | 69688 KB | Output is correct |
84 | Correct | 439 ms | 69612 KB | Output is correct |
85 | Correct | 455 ms | 69508 KB | Output is correct |
86 | Correct | 133 ms | 26432 KB | Output is correct |
87 | Correct | 0 ms | 204 KB | Output is correct |