답안 #316729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316729 2020-10-27T15:13:23 Z Temmie 이상한 기계 (APIO19_strange_device) C++17
100 / 100
849 ms 69732 KB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	ll n, a, b; std::cin >> n >> a >> b;
	ll val = 1LL << 60LL, c = 0;
	std::vector <std::pair <ll, ll>> p(n), v;
	for (auto& P : p) std::cin >> P.first >> P.second;
	int gcd = std::__gcd(a, b + 1);
	if ((a / gcd) <= val / b) c = (a / gcd) * b;
	for (auto& x : p) {
		ll l = x.first, r = x.second;
		if (c && r - l + 1LL >= c) {
			std::cout << c << "\n";
			return 0;
		}
		if (c) l %= c, r %= c;
		if (l <= r) v.push_back({ l, r });
		else v.push_back({ 0LL, r }), v.push_back({ l, c - 1LL });
	}
	ll last = -1, to = 0;
	std::sort(v.begin(), v.end());
	ll ans = 0;
	for (auto& x : v) {
		ll l = x.first, r = x.second;
		if (last == -1LL) to = r, last = l;
		else if (to < l) {
			ans += to - last + 1LL;
			to = r, last = l;
		} else to = std::max(to, r);
	}
	if (last != -1LL) ans += to - last + 1LL;
	std::cout << ans << "\n";
	//std::cout.flush(); std::cin >> n;
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 52 ms 7792 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 344 ms 35456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 37728 KB Output is correct
3 Correct 462 ms 37732 KB Output is correct
4 Correct 458 ms 37732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 37728 KB Output is correct
3 Correct 462 ms 37732 KB Output is correct
4 Correct 458 ms 37732 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 462 ms 37732 KB Output is correct
7 Correct 462 ms 37732 KB Output is correct
8 Correct 466 ms 37712 KB Output is correct
9 Correct 503 ms 40292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 468 ms 37728 KB Output is correct
3 Correct 462 ms 37732 KB Output is correct
4 Correct 458 ms 37732 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 47 ms 7828 KB Output is correct
7 Correct 53 ms 7792 KB Output is correct
8 Correct 47 ms 7792 KB Output is correct
9 Correct 48 ms 7792 KB Output is correct
10 Correct 46 ms 7792 KB Output is correct
11 Correct 50 ms 7792 KB Output is correct
12 Correct 45 ms 7792 KB Output is correct
13 Correct 49 ms 7824 KB Output is correct
14 Correct 46 ms 7792 KB Output is correct
15 Correct 51 ms 7792 KB Output is correct
16 Correct 51 ms 7920 KB Output is correct
17 Correct 47 ms 7792 KB Output is correct
18 Correct 474 ms 49120 KB Output is correct
19 Correct 849 ms 50128 KB Output is correct
20 Correct 512 ms 50532 KB Output is correct
21 Correct 51 ms 7828 KB Output is correct
22 Correct 44 ms 7792 KB Output is correct
23 Correct 154 ms 26600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 50 ms 7792 KB Output is correct
3 Correct 51 ms 7792 KB Output is correct
4 Correct 545 ms 50636 KB Output is correct
5 Correct 50 ms 7792 KB Output is correct
6 Correct 50 ms 7792 KB Output is correct
7 Correct 49 ms 7792 KB Output is correct
8 Correct 52 ms 7792 KB Output is correct
9 Correct 50 ms 7792 KB Output is correct
10 Correct 50 ms 7792 KB Output is correct
11 Correct 50 ms 7792 KB Output is correct
12 Correct 44 ms 7792 KB Output is correct
13 Correct 50 ms 7792 KB Output is correct
14 Correct 517 ms 41604 KB Output is correct
15 Correct 52 ms 7924 KB Output is correct
16 Correct 481 ms 69732 KB Output is correct
17 Correct 457 ms 37728 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 52 ms 7792 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 344 ms 35456 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 468 ms 37728 KB Output is correct
31 Correct 462 ms 37732 KB Output is correct
32 Correct 458 ms 37732 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 462 ms 37732 KB Output is correct
35 Correct 462 ms 37732 KB Output is correct
36 Correct 466 ms 37712 KB Output is correct
37 Correct 503 ms 40292 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 47 ms 7828 KB Output is correct
40 Correct 53 ms 7792 KB Output is correct
41 Correct 47 ms 7792 KB Output is correct
42 Correct 48 ms 7792 KB Output is correct
43 Correct 46 ms 7792 KB Output is correct
44 Correct 50 ms 7792 KB Output is correct
45 Correct 45 ms 7792 KB Output is correct
46 Correct 49 ms 7824 KB Output is correct
47 Correct 46 ms 7792 KB Output is correct
48 Correct 51 ms 7792 KB Output is correct
49 Correct 51 ms 7920 KB Output is correct
50 Correct 47 ms 7792 KB Output is correct
51 Correct 474 ms 49120 KB Output is correct
52 Correct 849 ms 50128 KB Output is correct
53 Correct 512 ms 50532 KB Output is correct
54 Correct 51 ms 7828 KB Output is correct
55 Correct 44 ms 7792 KB Output is correct
56 Correct 154 ms 26600 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 50 ms 7792 KB Output is correct
59 Correct 51 ms 7792 KB Output is correct
60 Correct 545 ms 50636 KB Output is correct
61 Correct 50 ms 7792 KB Output is correct
62 Correct 50 ms 7792 KB Output is correct
63 Correct 49 ms 7792 KB Output is correct
64 Correct 52 ms 7792 KB Output is correct
65 Correct 50 ms 7792 KB Output is correct
66 Correct 50 ms 7792 KB Output is correct
67 Correct 50 ms 7792 KB Output is correct
68 Correct 44 ms 7792 KB Output is correct
69 Correct 50 ms 7792 KB Output is correct
70 Correct 517 ms 41604 KB Output is correct
71 Correct 52 ms 7924 KB Output is correct
72 Correct 481 ms 69732 KB Output is correct
73 Correct 457 ms 37728 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 5 ms 1280 KB Output is correct
80 Correct 546 ms 39732 KB Output is correct
81 Correct 549 ms 39652 KB Output is correct
82 Correct 513 ms 51300 KB Output is correct
83 Correct 501 ms 37732 KB Output is correct
84 Correct 505 ms 42852 KB Output is correct
85 Correct 505 ms 42852 KB Output is correct
86 Correct 144 ms 26476 KB Output is correct
87 Correct 1 ms 384 KB Output is correct