답안 #1044709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044709 2024-08-05T12:40:05 Z vjudge1 이상한 기계 (APIO19_strange_device) C++17
100 / 100
280 ms 40880 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int C = inf;

int32_t main(){
	fast
	int n, a, b;
	cin >> n >> a >> b;
	__int128__ g = gcd(a, b + 1);
	__int128__ temp = (__int128__)a / g * b;
	if(temp > C) {
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int l, r;
			cin >> l >> r;
			sum += r - l + 1;
		}
		cout << sum;
		return 0;
	}
	int tekrar = temp;
	vector <pair<int, int> > ranges;
	for(int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		if(r - l + 1 >= tekrar) {
			cout << tekrar;
			return 0;
		}
		int ll = l % tekrar, rr = r % tekrar;
		if(ll <= rr) {
			ranges.push_back({ll, rr});
		}
		else {
			ranges.push_back({0, rr});
			ranges.push_back({ll, tekrar - 1});
		}
	}
	sort(ranges.begin(), ranges.end());
	int lastr = -inf, ans = 0;
	for(auto [l, r]:ranges) {
		if(l > lastr) {
			ans += r - l + 1;
		}
		else {
			ans += max(0ll, r - lastr);
		}
		lastr = max(lastr, r);
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 736 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 736 KB Output is correct
17 Correct 29 ms 2520 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 146 ms 17576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 252 ms 19760 KB Output is correct
3 Correct 241 ms 40228 KB Output is correct
4 Correct 236 ms 40276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 252 ms 19760 KB Output is correct
3 Correct 241 ms 40228 KB Output is correct
4 Correct 236 ms 40276 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 241 ms 40684 KB Output is correct
7 Correct 232 ms 40268 KB Output is correct
8 Correct 237 ms 40368 KB Output is correct
9 Correct 253 ms 40112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 252 ms 19760 KB Output is correct
3 Correct 241 ms 40228 KB Output is correct
4 Correct 236 ms 40276 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 22 ms 4832 KB Output is correct
7 Correct 24 ms 4684 KB Output is correct
8 Correct 24 ms 5068 KB Output is correct
9 Correct 25 ms 4812 KB Output is correct
10 Correct 23 ms 4804 KB Output is correct
11 Correct 26 ms 4708 KB Output is correct
12 Correct 25 ms 4808 KB Output is correct
13 Correct 27 ms 4812 KB Output is correct
14 Correct 23 ms 4812 KB Output is correct
15 Correct 29 ms 4692 KB Output is correct
16 Correct 27 ms 4808 KB Output is correct
17 Correct 25 ms 4600 KB Output is correct
18 Correct 232 ms 40368 KB Output is correct
19 Correct 244 ms 40164 KB Output is correct
20 Correct 269 ms 40208 KB Output is correct
21 Correct 25 ms 4812 KB Output is correct
22 Correct 23 ms 4804 KB Output is correct
23 Correct 70 ms 17140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 25 ms 2832 KB Output is correct
3 Correct 24 ms 2608 KB Output is correct
4 Correct 276 ms 40368 KB Output is correct
5 Correct 26 ms 4812 KB Output is correct
6 Correct 27 ms 4748 KB Output is correct
7 Correct 26 ms 4688 KB Output is correct
8 Correct 26 ms 4808 KB Output is correct
9 Correct 25 ms 4812 KB Output is correct
10 Correct 31 ms 4816 KB Output is correct
11 Correct 26 ms 4628 KB Output is correct
12 Correct 22 ms 4736 KB Output is correct
13 Correct 30 ms 4804 KB Output is correct
14 Correct 272 ms 40092 KB Output is correct
15 Correct 24 ms 4816 KB Output is correct
16 Correct 233 ms 40196 KB Output is correct
17 Correct 225 ms 40064 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 736 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 736 KB Output is correct
17 Correct 29 ms 2520 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 146 ms 17576 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 252 ms 19760 KB Output is correct
31 Correct 241 ms 40228 KB Output is correct
32 Correct 236 ms 40276 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 241 ms 40684 KB Output is correct
35 Correct 232 ms 40268 KB Output is correct
36 Correct 237 ms 40368 KB Output is correct
37 Correct 253 ms 40112 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 22 ms 4832 KB Output is correct
40 Correct 24 ms 4684 KB Output is correct
41 Correct 24 ms 5068 KB Output is correct
42 Correct 25 ms 4812 KB Output is correct
43 Correct 23 ms 4804 KB Output is correct
44 Correct 26 ms 4708 KB Output is correct
45 Correct 25 ms 4808 KB Output is correct
46 Correct 27 ms 4812 KB Output is correct
47 Correct 23 ms 4812 KB Output is correct
48 Correct 29 ms 4692 KB Output is correct
49 Correct 27 ms 4808 KB Output is correct
50 Correct 25 ms 4600 KB Output is correct
51 Correct 232 ms 40368 KB Output is correct
52 Correct 244 ms 40164 KB Output is correct
53 Correct 269 ms 40208 KB Output is correct
54 Correct 25 ms 4812 KB Output is correct
55 Correct 23 ms 4804 KB Output is correct
56 Correct 70 ms 17140 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 25 ms 2832 KB Output is correct
59 Correct 24 ms 2608 KB Output is correct
60 Correct 276 ms 40368 KB Output is correct
61 Correct 26 ms 4812 KB Output is correct
62 Correct 27 ms 4748 KB Output is correct
63 Correct 26 ms 4688 KB Output is correct
64 Correct 26 ms 4808 KB Output is correct
65 Correct 25 ms 4812 KB Output is correct
66 Correct 31 ms 4816 KB Output is correct
67 Correct 26 ms 4628 KB Output is correct
68 Correct 22 ms 4736 KB Output is correct
69 Correct 30 ms 4804 KB Output is correct
70 Correct 272 ms 40092 KB Output is correct
71 Correct 24 ms 4816 KB Output is correct
72 Correct 233 ms 40196 KB Output is correct
73 Correct 225 ms 40064 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 344 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 1152 KB Output is correct
80 Correct 280 ms 40876 KB Output is correct
81 Correct 263 ms 40880 KB Output is correct
82 Correct 266 ms 40200 KB Output is correct
83 Correct 251 ms 39856 KB Output is correct
84 Correct 254 ms 40400 KB Output is correct
85 Correct 262 ms 39988 KB Output is correct
86 Correct 75 ms 16320 KB Output is correct
87 Correct 0 ms 344 KB Output is correct