답안 #393918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393918 2021-04-24T22:17:05 Z ritul_kr_singh 이상한 기계 (APIO19_strange_device) C++17
100 / 100
585 ms 53400 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

const int INF = 1e18;

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	int n, A, B, l, r; cin >> n >> A >> B;

	int g = A / __gcd(A, B + 1LL);

	if(g > (INF + 5LL) / B) g = INF + 5;
	else g *= B;

	vector<array<int, 2>> q;
	bool all = false;

	while(n--){
		cin >> l >> r;
		int lm = l % g, rm = r % g;
		// if(l + (g - lm) <= r) q.push_back({lm, g-1}), q.push_back({0, rm});
		// else q.push_back({lm, rm});
		all = all or (r - l + 1LL >= g);
		if(lm <= rm) q.push_back({lm, rm});
		else q.push_back({lm, g-1LL}), q.push_back({0, rm});
	}

	int res = 0;
	l = -1, r = -2;
	sort(q.begin(), q.end());

	for(auto &i : q){
		if(r < i[0]){
			res += r - l + 1LL;
			l = i[0], r = i[1];
		}else r = max(r, i[1]);
	}

	res += r - l + 1LL;

	if(all) res = g;

	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 5 ms 976 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 976 KB Output is correct
17 Correct 54 ms 5656 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 501 ms 41312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 487 ms 16808 KB Output is correct
3 Correct 475 ms 16780 KB Output is correct
4 Correct 585 ms 16808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 487 ms 16808 KB Output is correct
3 Correct 475 ms 16780 KB Output is correct
4 Correct 585 ms 16808 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 480 ms 16784 KB Output is correct
7 Correct 478 ms 16836 KB Output is correct
8 Correct 476 ms 16804 KB Output is correct
9 Correct 512 ms 16752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 487 ms 16808 KB Output is correct
3 Correct 475 ms 16780 KB Output is correct
4 Correct 585 ms 16808 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 48 ms 2504 KB Output is correct
7 Correct 52 ms 2416 KB Output is correct
8 Correct 47 ms 2436 KB Output is correct
9 Correct 47 ms 2504 KB Output is correct
10 Correct 46 ms 2504 KB Output is correct
11 Correct 49 ms 2452 KB Output is correct
12 Correct 45 ms 2548 KB Output is correct
13 Correct 49 ms 2488 KB Output is correct
14 Correct 46 ms 2408 KB Output is correct
15 Correct 51 ms 2444 KB Output is correct
16 Correct 52 ms 5696 KB Output is correct
17 Correct 48 ms 5692 KB Output is correct
18 Correct 491 ms 53292 KB Output is correct
19 Correct 483 ms 53268 KB Output is correct
20 Correct 538 ms 53400 KB Output is correct
21 Correct 52 ms 5692 KB Output is correct
22 Correct 48 ms 5696 KB Output is correct
23 Correct 160 ms 18420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 50 ms 2492 KB Output is correct
3 Correct 50 ms 2504 KB Output is correct
4 Correct 568 ms 16836 KB Output is correct
5 Correct 49 ms 2496 KB Output is correct
6 Correct 50 ms 2492 KB Output is correct
7 Correct 51 ms 2412 KB Output is correct
8 Correct 51 ms 2436 KB Output is correct
9 Correct 50 ms 2444 KB Output is correct
10 Correct 50 ms 2524 KB Output is correct
11 Correct 62 ms 2496 KB Output is correct
12 Correct 44 ms 2456 KB Output is correct
13 Correct 50 ms 2504 KB Output is correct
14 Correct 520 ms 16820 KB Output is correct
15 Correct 51 ms 5688 KB Output is correct
16 Correct 519 ms 53240 KB Output is correct
17 Correct 499 ms 53228 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 5 ms 976 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 976 KB Output is correct
17 Correct 54 ms 5656 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 501 ms 41312 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 487 ms 16808 KB Output is correct
31 Correct 475 ms 16780 KB Output is correct
32 Correct 585 ms 16808 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 480 ms 16784 KB Output is correct
35 Correct 478 ms 16836 KB Output is correct
36 Correct 476 ms 16804 KB Output is correct
37 Correct 512 ms 16752 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 48 ms 2504 KB Output is correct
40 Correct 52 ms 2416 KB Output is correct
41 Correct 47 ms 2436 KB Output is correct
42 Correct 47 ms 2504 KB Output is correct
43 Correct 46 ms 2504 KB Output is correct
44 Correct 49 ms 2452 KB Output is correct
45 Correct 45 ms 2548 KB Output is correct
46 Correct 49 ms 2488 KB Output is correct
47 Correct 46 ms 2408 KB Output is correct
48 Correct 51 ms 2444 KB Output is correct
49 Correct 52 ms 5696 KB Output is correct
50 Correct 48 ms 5692 KB Output is correct
51 Correct 491 ms 53292 KB Output is correct
52 Correct 483 ms 53268 KB Output is correct
53 Correct 538 ms 53400 KB Output is correct
54 Correct 52 ms 5692 KB Output is correct
55 Correct 48 ms 5696 KB Output is correct
56 Correct 160 ms 18420 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 50 ms 2492 KB Output is correct
59 Correct 50 ms 2504 KB Output is correct
60 Correct 568 ms 16836 KB Output is correct
61 Correct 49 ms 2496 KB Output is correct
62 Correct 50 ms 2492 KB Output is correct
63 Correct 51 ms 2412 KB Output is correct
64 Correct 51 ms 2436 KB Output is correct
65 Correct 50 ms 2444 KB Output is correct
66 Correct 50 ms 2524 KB Output is correct
67 Correct 62 ms 2496 KB Output is correct
68 Correct 44 ms 2456 KB Output is correct
69 Correct 50 ms 2504 KB Output is correct
70 Correct 520 ms 16820 KB Output is correct
71 Correct 51 ms 5688 KB Output is correct
72 Correct 519 ms 53240 KB Output is correct
73 Correct 499 ms 53228 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 316 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 5 ms 1060 KB Output is correct
80 Correct 570 ms 53196 KB Output is correct
81 Correct 578 ms 53260 KB Output is correct
82 Correct 572 ms 53232 KB Output is correct
83 Correct 549 ms 53184 KB Output is correct
84 Correct 540 ms 53244 KB Output is correct
85 Correct 548 ms 53276 KB Output is correct
86 Correct 232 ms 18408 KB Output is correct
87 Correct 1 ms 204 KB Output is correct