# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125472 | 2019-07-05T11:58:06 Z | arnold518 | 이상한 기계 (APIO19_strange_device) | C++14 | 647 ms | 33136 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const ll INF = numeric_limits<ll>::max(); ll a, b, n, ans; pll arr[MAXN+10]; int main() { int i, j; scanf("%lld%lld%lld", &n, &a, &b); for(i=1; i<=n; i++) scanf("%lld%lld", &arr[i].first, &arr[i].second); ll g=__gcd(a, (b+1)%a); a/=g; bool over = false; if(INF/b<a) over=true; else a*=b; if(over) { for(i=1; i<=n; i++) ans+=arr[i].second-arr[i].first+1; return !printf("%lld", ans); } vector<pll> A; for(i=1; i<=n; i++) { if(arr[i].second-arr[i].first+1>=a) return !printf("%lld", a); arr[i].first%=a; arr[i].second%=a; if(arr[i].second<arr[i].first) A.push_back({arr[i].first, a-1}), A.push_back({0, arr[i].second}); else A.push_back(arr[i]); } sort(A.begin(), A.end()); ll s=-1, e=-2; for(i=0; i<A.size(); i++) { if(e<A[i].first) ans+=e-s+1, s=A[i].first; e=max(e, A[i].second); } ans+=e-s+1; printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 8 ms | 1144 KB | Output is correct |
3 | Correct | 8 ms | 888 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 296 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 9 ms | 1008 KB | Output is correct |
17 | Correct | 64 ms | 4200 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 300 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 440 KB | Output is correct |
5 | Correct | 443 ms | 33092 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 33128 KB | Output is correct |
3 | Correct | 570 ms | 33008 KB | Output is correct |
4 | Correct | 566 ms | 33000 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 33128 KB | Output is correct |
3 | Correct | 570 ms | 33008 KB | Output is correct |
4 | Correct | 566 ms | 33000 KB | Output is correct |
5 | Correct | 2 ms | 368 KB | Output is correct |
6 | Correct | 563 ms | 33136 KB | Output is correct |
7 | Correct | 580 ms | 33004 KB | Output is correct |
8 | Correct | 562 ms | 32752 KB | Output is correct |
9 | Correct | 619 ms | 32756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 583 ms | 33128 KB | Output is correct |
3 | Correct | 570 ms | 33008 KB | Output is correct |
4 | Correct | 566 ms | 33000 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 59 ms | 4840 KB | Output is correct |
7 | Correct | 61 ms | 4456 KB | Output is correct |
8 | Correct | 56 ms | 4456 KB | Output is correct |
9 | Correct | 58 ms | 4460 KB | Output is correct |
10 | Correct | 57 ms | 4460 KB | Output is correct |
11 | Correct | 60 ms | 4456 KB | Output is correct |
12 | Correct | 59 ms | 4456 KB | Output is correct |
13 | Correct | 62 ms | 4432 KB | Output is correct |
14 | Correct | 57 ms | 4432 KB | Output is correct |
15 | Correct | 64 ms | 4524 KB | Output is correct |
16 | Correct | 63 ms | 4588 KB | Output is correct |
17 | Correct | 58 ms | 4428 KB | Output is correct |
18 | Correct | 578 ms | 32748 KB | Output is correct |
19 | Correct | 553 ms | 32632 KB | Output is correct |
20 | Correct | 617 ms | 32632 KB | Output is correct |
21 | Correct | 61 ms | 4596 KB | Output is correct |
22 | Correct | 56 ms | 4392 KB | Output is correct |
23 | Correct | 210 ms | 14212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 63 ms | 4416 KB | Output is correct |
3 | Correct | 61 ms | 4168 KB | Output is correct |
4 | Correct | 634 ms | 32828 KB | Output is correct |
5 | Correct | 61 ms | 4396 KB | Output is correct |
6 | Correct | 61 ms | 4456 KB | Output is correct |
7 | Correct | 61 ms | 4460 KB | Output is correct |
8 | Correct | 63 ms | 4500 KB | Output is correct |
9 | Correct | 61 ms | 4460 KB | Output is correct |
10 | Correct | 61 ms | 4420 KB | Output is correct |
11 | Correct | 60 ms | 4468 KB | Output is correct |
12 | Correct | 56 ms | 4384 KB | Output is correct |
13 | Correct | 62 ms | 4456 KB | Output is correct |
14 | Correct | 625 ms | 32852 KB | Output is correct |
15 | Correct | 63 ms | 4584 KB | Output is correct |
16 | Correct | 582 ms | 32780 KB | Output is correct |
17 | Correct | 574 ms | 32688 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 8 ms | 1144 KB | Output is correct |
3 | Correct | 8 ms | 888 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 296 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 9 ms | 1008 KB | Output is correct |
17 | Correct | 64 ms | 4200 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 300 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 2 ms | 256 KB | Output is correct |
24 | Correct | 2 ms | 256 KB | Output is correct |
25 | Correct | 3 ms | 376 KB | Output is correct |
26 | Correct | 3 ms | 376 KB | Output is correct |
27 | Correct | 3 ms | 440 KB | Output is correct |
28 | Correct | 443 ms | 33092 KB | Output is correct |
29 | Correct | 2 ms | 256 KB | Output is correct |
30 | Correct | 583 ms | 33128 KB | Output is correct |
31 | Correct | 570 ms | 33008 KB | Output is correct |
32 | Correct | 566 ms | 33000 KB | Output is correct |
33 | Correct | 2 ms | 368 KB | Output is correct |
34 | Correct | 563 ms | 33136 KB | Output is correct |
35 | Correct | 580 ms | 33004 KB | Output is correct |
36 | Correct | 562 ms | 32752 KB | Output is correct |
37 | Correct | 619 ms | 32756 KB | Output is correct |
38 | Correct | 2 ms | 256 KB | Output is correct |
39 | Correct | 59 ms | 4840 KB | Output is correct |
40 | Correct | 61 ms | 4456 KB | Output is correct |
41 | Correct | 56 ms | 4456 KB | Output is correct |
42 | Correct | 58 ms | 4460 KB | Output is correct |
43 | Correct | 57 ms | 4460 KB | Output is correct |
44 | Correct | 60 ms | 4456 KB | Output is correct |
45 | Correct | 59 ms | 4456 KB | Output is correct |
46 | Correct | 62 ms | 4432 KB | Output is correct |
47 | Correct | 57 ms | 4432 KB | Output is correct |
48 | Correct | 64 ms | 4524 KB | Output is correct |
49 | Correct | 63 ms | 4588 KB | Output is correct |
50 | Correct | 58 ms | 4428 KB | Output is correct |
51 | Correct | 578 ms | 32748 KB | Output is correct |
52 | Correct | 553 ms | 32632 KB | Output is correct |
53 | Correct | 617 ms | 32632 KB | Output is correct |
54 | Correct | 61 ms | 4596 KB | Output is correct |
55 | Correct | 56 ms | 4392 KB | Output is correct |
56 | Correct | 210 ms | 14212 KB | Output is correct |
57 | Correct | 2 ms | 256 KB | Output is correct |
58 | Correct | 63 ms | 4416 KB | Output is correct |
59 | Correct | 61 ms | 4168 KB | Output is correct |
60 | Correct | 634 ms | 32828 KB | Output is correct |
61 | Correct | 61 ms | 4396 KB | Output is correct |
62 | Correct | 61 ms | 4456 KB | Output is correct |
63 | Correct | 61 ms | 4460 KB | Output is correct |
64 | Correct | 63 ms | 4500 KB | Output is correct |
65 | Correct | 61 ms | 4460 KB | Output is correct |
66 | Correct | 61 ms | 4420 KB | Output is correct |
67 | Correct | 60 ms | 4468 KB | Output is correct |
68 | Correct | 56 ms | 4384 KB | Output is correct |
69 | Correct | 62 ms | 4456 KB | Output is correct |
70 | Correct | 625 ms | 32852 KB | Output is correct |
71 | Correct | 63 ms | 4584 KB | Output is correct |
72 | Correct | 582 ms | 32780 KB | Output is correct |
73 | Correct | 574 ms | 32688 KB | Output is correct |
74 | Correct | 2 ms | 256 KB | Output is correct |
75 | Correct | 2 ms | 256 KB | Output is correct |
76 | Correct | 2 ms | 256 KB | Output is correct |
77 | Correct | 2 ms | 256 KB | Output is correct |
78 | Correct | 2 ms | 256 KB | Output is correct |
79 | Correct | 7 ms | 888 KB | Output is correct |
80 | Correct | 644 ms | 32592 KB | Output is correct |
81 | Correct | 631 ms | 32648 KB | Output is correct |
82 | Correct | 604 ms | 32684 KB | Output is correct |
83 | Correct | 603 ms | 32704 KB | Output is correct |
84 | Correct | 606 ms | 32596 KB | Output is correct |
85 | Correct | 647 ms | 32588 KB | Output is correct |
86 | Correct | 208 ms | 13948 KB | Output is correct |
87 | Correct | 2 ms | 352 KB | Output is correct |