답안 #210743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210743 2020-03-18T09:46:34 Z islingr 이상한 기계 (APIO19_strange_device) C++14
100 / 100
2304 ms 16504 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; }
};

const 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() { cout << solve(); }
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 26 ms 888 KB Output is correct
3 Correct 28 ms 892 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 26 ms 888 KB Output is correct
17 Correct 238 ms 2296 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 1508 ms 16456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2134 ms 16504 KB Output is correct
3 Correct 2117 ms 16376 KB Output is correct
4 Correct 2139 ms 16376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2134 ms 16504 KB Output is correct
3 Correct 2117 ms 16376 KB Output is correct
4 Correct 2139 ms 16376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 2144 ms 16376 KB Output is correct
7 Correct 2124 ms 16376 KB Output is correct
8 Correct 2132 ms 16376 KB Output is correct
9 Correct 2215 ms 16376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2134 ms 16504 KB Output is correct
3 Correct 2117 ms 16376 KB Output is correct
4 Correct 2139 ms 16376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 221 ms 2136 KB Output is correct
7 Correct 222 ms 2168 KB Output is correct
8 Correct 216 ms 2168 KB Output is correct
9 Correct 219 ms 2144 KB Output is correct
10 Correct 215 ms 2296 KB Output is correct
11 Correct 223 ms 2296 KB Output is correct
12 Correct 222 ms 2296 KB Output is correct
13 Correct 224 ms 2296 KB Output is correct
14 Correct 215 ms 2296 KB Output is correct
15 Correct 226 ms 2296 KB Output is correct
16 Correct 225 ms 2296 KB Output is correct
17 Correct 222 ms 2296 KB Output is correct
18 Correct 2174 ms 16400 KB Output is correct
19 Correct 2151 ms 16376 KB Output is correct
20 Correct 2215 ms 16336 KB Output is correct
21 Correct 223 ms 2168 KB Output is correct
22 Correct 214 ms 2168 KB Output is correct
23 Correct 717 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 223 ms 2168 KB Output is correct
3 Correct 223 ms 2100 KB Output is correct
4 Correct 2264 ms 16248 KB Output is correct
5 Correct 220 ms 2168 KB Output is correct
6 Correct 222 ms 2168 KB Output is correct
7 Correct 221 ms 2168 KB Output is correct
8 Correct 221 ms 2168 KB Output is correct
9 Correct 222 ms 2168 KB Output is correct
10 Correct 218 ms 2168 KB Output is correct
11 Correct 218 ms 2168 KB Output is correct
12 Correct 215 ms 2168 KB Output is correct
13 Correct 225 ms 2168 KB Output is correct
14 Correct 2249 ms 16204 KB Output is correct
15 Correct 222 ms 2168 KB Output is correct
16 Correct 2108 ms 16248 KB Output is correct
17 Correct 2144 ms 16248 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 26 ms 888 KB Output is correct
3 Correct 28 ms 892 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 26 ms 888 KB Output is correct
17 Correct 238 ms 2296 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 1508 ms 16456 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 2134 ms 16504 KB Output is correct
31 Correct 2117 ms 16376 KB Output is correct
32 Correct 2139 ms 16376 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 2144 ms 16376 KB Output is correct
35 Correct 2124 ms 16376 KB Output is correct
36 Correct 2132 ms 16376 KB Output is correct
37 Correct 2215 ms 16376 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 221 ms 2136 KB Output is correct
40 Correct 222 ms 2168 KB Output is correct
41 Correct 216 ms 2168 KB Output is correct
42 Correct 219 ms 2144 KB Output is correct
43 Correct 215 ms 2296 KB Output is correct
44 Correct 223 ms 2296 KB Output is correct
45 Correct 222 ms 2296 KB Output is correct
46 Correct 224 ms 2296 KB Output is correct
47 Correct 215 ms 2296 KB Output is correct
48 Correct 226 ms 2296 KB Output is correct
49 Correct 225 ms 2296 KB Output is correct
50 Correct 222 ms 2296 KB Output is correct
51 Correct 2174 ms 16400 KB Output is correct
52 Correct 2151 ms 16376 KB Output is correct
53 Correct 2215 ms 16336 KB Output is correct
54 Correct 223 ms 2168 KB Output is correct
55 Correct 214 ms 2168 KB Output is correct
56 Correct 717 ms 5880 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 223 ms 2168 KB Output is correct
59 Correct 223 ms 2100 KB Output is correct
60 Correct 2264 ms 16248 KB Output is correct
61 Correct 220 ms 2168 KB Output is correct
62 Correct 222 ms 2168 KB Output is correct
63 Correct 221 ms 2168 KB Output is correct
64 Correct 221 ms 2168 KB Output is correct
65 Correct 222 ms 2168 KB Output is correct
66 Correct 218 ms 2168 KB Output is correct
67 Correct 218 ms 2168 KB Output is correct
68 Correct 215 ms 2168 KB Output is correct
69 Correct 225 ms 2168 KB Output is correct
70 Correct 2249 ms 16204 KB Output is correct
71 Correct 222 ms 2168 KB Output is correct
72 Correct 2108 ms 16248 KB Output is correct
73 Correct 2144 ms 16248 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 5 ms 256 KB Output is correct
76 Correct 5 ms 256 KB Output is correct
77 Correct 5 ms 376 KB Output is correct
78 Correct 4 ms 256 KB Output is correct
79 Correct 26 ms 760 KB Output is correct
80 Correct 2245 ms 16248 KB Output is correct
81 Correct 2250 ms 16252 KB Output is correct
82 Correct 2191 ms 16276 KB Output is correct
83 Correct 2248 ms 16252 KB Output is correct
84 Correct 2304 ms 16152 KB Output is correct
85 Correct 2225 ms 16248 KB Output is correct
86 Correct 701 ms 5752 KB Output is correct
87 Correct 5 ms 256 KB Output is correct