답안 #258915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258915 2020-08-06T18:36:41 Z parsa_mobed 이상한 기계 (APIO19_strange_device) C++14
100 / 100
2359 ms 18968 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e6 + 5, inf = 1e18 + 10;
vector <pii> seg;

int32_t main() {
	int n, A, B, ans = 0; cin >> n >> A >> B;
	A = A / __gcd(A, B + 1);
	int AB = A*B;
	if (inf/(long double)A <= B) {
		for (int i = 0,l,r; i < n; i++) cin >> l >> r, ans += r - l + 1;
		cout << ans << "\n";
		return 0;
	}
	for (int i = 0; i < n; i++) {
		int l, r; cin >> l >> r;
		int L = l + (l % AB ? AB - l % AB : 0);
		if (L + AB <= r + 1) return cout << AB << "\n", 0;
		if (l/AB == r/AB) seg.push_back({l % AB, r % AB});
		else seg.push_back({l % AB, AB - 1}), seg.push_back({0, r % AB}); 
	}
	sort(seg.begin(), seg.end());
	int cl = seg[0].F, cr = seg[0].S;
	for (pii p : seg) {
		int l = p.F, r = p.S;
		if (l <= cr) cr = max(cr, r);
		else ans += cr - cl + 1, cl = l, cr = r;
	}
	cout << ans + cr - cl + 1 << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 22 ms 1024 KB Output is correct
3 Correct 23 ms 1144 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 23 ms 1144 KB Output is correct
17 Correct 218 ms 3816 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1498 ms 18448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2134 ms 18048 KB Output is correct
3 Correct 2146 ms 18196 KB Output is correct
4 Correct 2109 ms 18256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2134 ms 18048 KB Output is correct
3 Correct 2146 ms 18196 KB Output is correct
4 Correct 2109 ms 18256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 2109 ms 18332 KB Output is correct
7 Correct 2120 ms 18308 KB Output is correct
8 Correct 2090 ms 18256 KB Output is correct
9 Correct 2143 ms 18252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2134 ms 18048 KB Output is correct
3 Correct 2146 ms 18196 KB Output is correct
4 Correct 2109 ms 18256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 211 ms 3752 KB Output is correct
7 Correct 210 ms 3820 KB Output is correct
8 Correct 209 ms 3820 KB Output is correct
9 Correct 211 ms 3816 KB Output is correct
10 Correct 208 ms 3820 KB Output is correct
11 Correct 211 ms 3820 KB Output is correct
12 Correct 210 ms 3820 KB Output is correct
13 Correct 215 ms 3816 KB Output is correct
14 Correct 214 ms 3816 KB Output is correct
15 Correct 218 ms 3780 KB Output is correct
16 Correct 215 ms 3816 KB Output is correct
17 Correct 211 ms 3820 KB Output is correct
18 Correct 2093 ms 18276 KB Output is correct
19 Correct 2089 ms 18284 KB Output is correct
20 Correct 2180 ms 18384 KB Output is correct
21 Correct 212 ms 3820 KB Output is correct
22 Correct 216 ms 3820 KB Output is correct
23 Correct 711 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 211 ms 3852 KB Output is correct
3 Correct 217 ms 3816 KB Output is correct
4 Correct 2177 ms 18256 KB Output is correct
5 Correct 217 ms 3820 KB Output is correct
6 Correct 214 ms 3832 KB Output is correct
7 Correct 215 ms 3820 KB Output is correct
8 Correct 214 ms 3820 KB Output is correct
9 Correct 217 ms 3820 KB Output is correct
10 Correct 216 ms 3820 KB Output is correct
11 Correct 216 ms 3692 KB Output is correct
12 Correct 212 ms 3688 KB Output is correct
13 Correct 216 ms 3948 KB Output is correct
14 Correct 2359 ms 18384 KB Output is correct
15 Correct 215 ms 3948 KB Output is correct
16 Correct 2136 ms 18428 KB Output is correct
17 Correct 2231 ms 18432 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 22 ms 1024 KB Output is correct
3 Correct 23 ms 1144 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 23 ms 1144 KB Output is correct
17 Correct 218 ms 3816 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1498 ms 18448 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2134 ms 18048 KB Output is correct
31 Correct 2146 ms 18196 KB Output is correct
32 Correct 2109 ms 18256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 2109 ms 18332 KB Output is correct
35 Correct 2120 ms 18308 KB Output is correct
36 Correct 2090 ms 18256 KB Output is correct
37 Correct 2143 ms 18252 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 211 ms 3752 KB Output is correct
40 Correct 210 ms 3820 KB Output is correct
41 Correct 209 ms 3820 KB Output is correct
42 Correct 211 ms 3816 KB Output is correct
43 Correct 208 ms 3820 KB Output is correct
44 Correct 211 ms 3820 KB Output is correct
45 Correct 210 ms 3820 KB Output is correct
46 Correct 215 ms 3816 KB Output is correct
47 Correct 214 ms 3816 KB Output is correct
48 Correct 218 ms 3780 KB Output is correct
49 Correct 215 ms 3816 KB Output is correct
50 Correct 211 ms 3820 KB Output is correct
51 Correct 2093 ms 18276 KB Output is correct
52 Correct 2089 ms 18284 KB Output is correct
53 Correct 2180 ms 18384 KB Output is correct
54 Correct 212 ms 3820 KB Output is correct
55 Correct 216 ms 3820 KB Output is correct
56 Correct 711 ms 10112 KB Output is correct
57 Correct 0 ms 256 KB Output is correct
58 Correct 211 ms 3852 KB Output is correct
59 Correct 217 ms 3816 KB Output is correct
60 Correct 2177 ms 18256 KB Output is correct
61 Correct 217 ms 3820 KB Output is correct
62 Correct 214 ms 3832 KB Output is correct
63 Correct 215 ms 3820 KB Output is correct
64 Correct 214 ms 3820 KB Output is correct
65 Correct 217 ms 3820 KB Output is correct
66 Correct 216 ms 3820 KB Output is correct
67 Correct 216 ms 3692 KB Output is correct
68 Correct 212 ms 3688 KB Output is correct
69 Correct 216 ms 3948 KB Output is correct
70 Correct 2359 ms 18384 KB Output is correct
71 Correct 215 ms 3948 KB Output is correct
72 Correct 2136 ms 18428 KB Output is correct
73 Correct 2231 ms 18432 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 22 ms 1024 KB Output is correct
80 Correct 2189 ms 18660 KB Output is correct
81 Correct 2159 ms 18640 KB Output is correct
82 Correct 2135 ms 18640 KB Output is correct
83 Correct 2136 ms 18968 KB Output is correct
84 Correct 2153 ms 18684 KB Output is correct
85 Correct 2274 ms 18736 KB Output is correct
86 Correct 723 ms 10484 KB Output is correct
87 Correct 1 ms 384 KB Output is correct