답안 #210772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210772 2020-03-18T10:30:34 Z islingr 이상한 기계 (APIO19_strange_device) C++14
100 / 100
650 ms 19204 KB
/*
	22/02/2020
	islingr
*/

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

#define all(x) begin(x), end(x)
#define eb(x...) emplace_back(x)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

struct event {
	ll l, r;
	event(ll a, ll b) : l{a}, r{b} { }
	bool operator<(const event &e) const { return r < e.r; }
};

constexpr ll inf = 2e18;

ll solve () {
	int n; ll a, b; cin >> n >> a >> b;
	ll g = __gcd(a, b + 1), p;

	if (a / g > inf / b) p = inf;
	else p = a / g * b;

	vector<event> v; v.reserve(2 * n);
	rep(i, 0, n) {
		ll l, r; cin >> l >> r;
		if (r - l + 1 < p) {
			l %= p; r %= p;
			if (l <= r) v.eb(l, r);
			else v.eb(0, r), v.eb(l, p - 1);
		} else return p;
	}
	sort(all(v));

	ll ans = 0;
	while (!v.empty()) {
		event top = v.back(); v.pop_back();
		while (!v.empty() && top.l <= v.back().r) {
			ckmin(top.l, v.back().l);
			v.pop_back();
		}
		ans += top.r - top.l + 1;
	}

	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	cout << solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 10 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 20 ms 888 KB Output is correct
17 Correct 65 ms 3576 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 11 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 13 ms 376 KB Output is correct
5 Correct 394 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 535 ms 18040 KB Output is correct
3 Correct 519 ms 19204 KB Output is correct
4 Correct 543 ms 18168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 535 ms 18040 KB Output is correct
3 Correct 519 ms 19204 KB Output is correct
4 Correct 543 ms 18168 KB Output is correct
5 Correct 7 ms 376 KB Output is correct
6 Correct 520 ms 18168 KB Output is correct
7 Correct 543 ms 18168 KB Output is correct
8 Correct 533 ms 18160 KB Output is correct
9 Correct 610 ms 18552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 535 ms 18040 KB Output is correct
3 Correct 519 ms 19204 KB Output is correct
4 Correct 543 ms 18168 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 59 ms 3832 KB Output is correct
7 Correct 66 ms 3840 KB Output is correct
8 Correct 58 ms 3832 KB Output is correct
9 Correct 68 ms 3768 KB Output is correct
10 Correct 57 ms 4856 KB Output is correct
11 Correct 62 ms 4088 KB Output is correct
12 Correct 96 ms 4728 KB Output is correct
13 Correct 85 ms 4856 KB Output is correct
14 Correct 56 ms 4856 KB Output is correct
15 Correct 79 ms 4856 KB Output is correct
16 Correct 62 ms 4860 KB Output is correct
17 Correct 77 ms 4856 KB Output is correct
18 Correct 531 ms 18936 KB Output is correct
19 Correct 513 ms 18424 KB Output is correct
20 Correct 599 ms 18168 KB Output is correct
21 Correct 73 ms 4088 KB Output is correct
22 Correct 55 ms 4088 KB Output is correct
23 Correct 163 ms 7800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 61 ms 4088 KB Output is correct
3 Correct 61 ms 4088 KB Output is correct
4 Correct 650 ms 18168 KB Output is correct
5 Correct 65 ms 4088 KB Output is correct
6 Correct 62 ms 4064 KB Output is correct
7 Correct 64 ms 4088 KB Output is correct
8 Correct 63 ms 4092 KB Output is correct
9 Correct 75 ms 4088 KB Output is correct
10 Correct 61 ms 4088 KB Output is correct
11 Correct 61 ms 4088 KB Output is correct
12 Correct 56 ms 4088 KB Output is correct
13 Correct 63 ms 4088 KB Output is correct
14 Correct 598 ms 18168 KB Output is correct
15 Correct 59 ms 4088 KB Output is correct
16 Correct 528 ms 18168 KB Output is correct
17 Correct 499 ms 18168 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 10 ms 888 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 10 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 20 ms 888 KB Output is correct
17 Correct 65 ms 3576 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 10 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 11 ms 376 KB Output is correct
22 Correct 5 ms 380 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 13 ms 376 KB Output is correct
28 Correct 394 ms 17656 KB Output is correct
29 Correct 13 ms 376 KB Output is correct
30 Correct 535 ms 18040 KB Output is correct
31 Correct 519 ms 19204 KB Output is correct
32 Correct 543 ms 18168 KB Output is correct
33 Correct 7 ms 376 KB Output is correct
34 Correct 520 ms 18168 KB Output is correct
35 Correct 543 ms 18168 KB Output is correct
36 Correct 533 ms 18160 KB Output is correct
37 Correct 610 ms 18552 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 59 ms 3832 KB Output is correct
40 Correct 66 ms 3840 KB Output is correct
41 Correct 58 ms 3832 KB Output is correct
42 Correct 68 ms 3768 KB Output is correct
43 Correct 57 ms 4856 KB Output is correct
44 Correct 62 ms 4088 KB Output is correct
45 Correct 96 ms 4728 KB Output is correct
46 Correct 85 ms 4856 KB Output is correct
47 Correct 56 ms 4856 KB Output is correct
48 Correct 79 ms 4856 KB Output is correct
49 Correct 62 ms 4860 KB Output is correct
50 Correct 77 ms 4856 KB Output is correct
51 Correct 531 ms 18936 KB Output is correct
52 Correct 513 ms 18424 KB Output is correct
53 Correct 599 ms 18168 KB Output is correct
54 Correct 73 ms 4088 KB Output is correct
55 Correct 55 ms 4088 KB Output is correct
56 Correct 163 ms 7800 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 61 ms 4088 KB Output is correct
59 Correct 61 ms 4088 KB Output is correct
60 Correct 650 ms 18168 KB Output is correct
61 Correct 65 ms 4088 KB Output is correct
62 Correct 62 ms 4064 KB Output is correct
63 Correct 64 ms 4088 KB Output is correct
64 Correct 63 ms 4092 KB Output is correct
65 Correct 75 ms 4088 KB Output is correct
66 Correct 61 ms 4088 KB Output is correct
67 Correct 61 ms 4088 KB Output is correct
68 Correct 56 ms 4088 KB Output is correct
69 Correct 63 ms 4088 KB Output is correct
70 Correct 598 ms 18168 KB Output is correct
71 Correct 59 ms 4088 KB Output is correct
72 Correct 528 ms 18168 KB Output is correct
73 Correct 499 ms 18168 KB Output is correct
74 Correct 5 ms 376 KB Output is correct
75 Correct 5 ms 376 KB Output is correct
76 Correct 5 ms 408 KB Output is correct
77 Correct 5 ms 376 KB Output is correct
78 Correct 5 ms 376 KB Output is correct
79 Correct 10 ms 888 KB Output is correct
80 Correct 624 ms 18400 KB Output is correct
81 Correct 635 ms 18404 KB Output is correct
82 Correct 584 ms 18424 KB Output is correct
83 Correct 604 ms 18300 KB Output is correct
84 Correct 587 ms 18168 KB Output is correct
85 Correct 584 ms 18168 KB Output is correct
86 Correct 169 ms 7816 KB Output is correct
87 Correct 8 ms 376 KB Output is correct