Submission #1044710

# Submission time Handle Problem Language Result Execution time Memory
1044710 2024-08-05T12:41:05 Z Onur_Ilgaz Strange Device (APIO19_strange_device) C++17
100 / 100
254 ms 18876 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 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 348 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 24 ms 2584 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 157 ms 17080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 219 ms 17460 KB Output is correct
3 Correct 221 ms 18356 KB Output is correct
4 Correct 232 ms 17456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 219 ms 17460 KB Output is correct
3 Correct 221 ms 18356 KB Output is correct
4 Correct 232 ms 17456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 234 ms 17944 KB Output is correct
7 Correct 218 ms 18224 KB Output is correct
8 Correct 215 ms 18100 KB Output is correct
9 Correct 244 ms 17332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 219 ms 17460 KB Output is correct
3 Correct 221 ms 18356 KB Output is correct
4 Correct 232 ms 17456 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 21 ms 2520 KB Output is correct
7 Correct 27 ms 2512 KB Output is correct
8 Correct 22 ms 2516 KB Output is correct
9 Correct 23 ms 2648 KB Output is correct
10 Correct 22 ms 2516 KB Output is correct
11 Correct 23 ms 2520 KB Output is correct
12 Correct 21 ms 2520 KB Output is correct
13 Correct 24 ms 2516 KB Output is correct
14 Correct 23 ms 2644 KB Output is correct
15 Correct 25 ms 2516 KB Output is correct
16 Correct 33 ms 2516 KB Output is correct
17 Correct 22 ms 2520 KB Output is correct
18 Correct 229 ms 18608 KB Output is correct
19 Correct 232 ms 17624 KB Output is correct
20 Correct 250 ms 18000 KB Output is correct
21 Correct 26 ms 2520 KB Output is correct
22 Correct 21 ms 2516 KB Output is correct
23 Correct 67 ms 9216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 25 ms 2520 KB Output is correct
3 Correct 24 ms 2520 KB Output is correct
4 Correct 252 ms 18848 KB Output is correct
5 Correct 25 ms 2520 KB Output is correct
6 Correct 25 ms 2516 KB Output is correct
7 Correct 26 ms 2576 KB Output is correct
8 Correct 26 ms 2520 KB Output is correct
9 Correct 23 ms 2572 KB Output is correct
10 Correct 25 ms 2516 KB Output is correct
11 Correct 24 ms 2588 KB Output is correct
12 Correct 20 ms 2520 KB Output is correct
13 Correct 25 ms 2516 KB Output is correct
14 Correct 247 ms 17848 KB Output is correct
15 Correct 24 ms 2588 KB Output is correct
16 Correct 219 ms 17336 KB Output is correct
17 Correct 234 ms 18352 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 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 348 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 24 ms 2584 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 0 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 348 KB Output is correct
28 Correct 157 ms 17080 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 219 ms 17460 KB Output is correct
31 Correct 221 ms 18356 KB Output is correct
32 Correct 232 ms 17456 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 234 ms 17944 KB Output is correct
35 Correct 218 ms 18224 KB Output is correct
36 Correct 215 ms 18100 KB Output is correct
37 Correct 244 ms 17332 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 21 ms 2520 KB Output is correct
40 Correct 27 ms 2512 KB Output is correct
41 Correct 22 ms 2516 KB Output is correct
42 Correct 23 ms 2648 KB Output is correct
43 Correct 22 ms 2516 KB Output is correct
44 Correct 23 ms 2520 KB Output is correct
45 Correct 21 ms 2520 KB Output is correct
46 Correct 24 ms 2516 KB Output is correct
47 Correct 23 ms 2644 KB Output is correct
48 Correct 25 ms 2516 KB Output is correct
49 Correct 33 ms 2516 KB Output is correct
50 Correct 22 ms 2520 KB Output is correct
51 Correct 229 ms 18608 KB Output is correct
52 Correct 232 ms 17624 KB Output is correct
53 Correct 250 ms 18000 KB Output is correct
54 Correct 26 ms 2520 KB Output is correct
55 Correct 21 ms 2516 KB Output is correct
56 Correct 67 ms 9216 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 25 ms 2520 KB Output is correct
59 Correct 24 ms 2520 KB Output is correct
60 Correct 252 ms 18848 KB Output is correct
61 Correct 25 ms 2520 KB Output is correct
62 Correct 25 ms 2516 KB Output is correct
63 Correct 26 ms 2576 KB Output is correct
64 Correct 26 ms 2520 KB Output is correct
65 Correct 23 ms 2572 KB Output is correct
66 Correct 25 ms 2516 KB Output is correct
67 Correct 24 ms 2588 KB Output is correct
68 Correct 20 ms 2520 KB Output is correct
69 Correct 25 ms 2516 KB Output is correct
70 Correct 247 ms 17848 KB Output is correct
71 Correct 24 ms 2588 KB Output is correct
72 Correct 219 ms 17336 KB Output is correct
73 Correct 234 ms 18352 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 2 ms 736 KB Output is correct
80 Correct 245 ms 18688 KB Output is correct
81 Correct 254 ms 17432 KB Output is correct
82 Correct 241 ms 17336 KB Output is correct
83 Correct 249 ms 18616 KB Output is correct
84 Correct 246 ms 18876 KB Output is correct
85 Correct 251 ms 17332 KB Output is correct
86 Correct 65 ms 9144 KB Output is correct
87 Correct 0 ms 344 KB Output is correct