Submission #1032628

# Submission time Handle Problem Language Result Execution time Memory
1032628 2024-07-24T04:30:53 Z Muhammet Strange Device (APIO19_strange_device) C++17
100 / 100
345 ms 69828 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second

const ll N = 1000005;
const ll M = 1e18;

ll T, n, a, b, l[N], r[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> a >> b;
	ll x = 0;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		x += (r[i]-l[i]+1);
	}
	ll m = __gcd(a,b+1);
	m = (a/m);
	ll k = 0;
	if(M/b < m) {
		cout << x;
		return 0;
	}
	k = m*b;
	vector <pair<ll,ll>> v;
	for(int i = 1; i <= n; i++){
		if(r[i]-l[i]+1 >= k){
			cout << k;
			return 0;
		}
		ll c = (l[i]%k), d = r[i]%k;
		if(c > d){
			v.push_back({c,k-1});
			v.push_back({0,d});
		}
		else {
			v.push_back({c,d});
		}
	}
	sort(v.begin(), v.end());
	ll mn = v[0].ff, mx = v[0].ss, ans = 0;
	for(auto i : v){
		if(i.ff > mx){
			ans += (mx-mn+1);
			mn = 1e18;
			mx = -1e18;
		}
		mn = min(i.ff,mn);
		mx = max(mx,i.ss);
	}
	if(mn <= mx){
		ans += (mx-mn+1);
	}
	
	cout << ans;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1232 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 464 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 1360 KB Output is correct
17 Correct 32 ms 7896 KB Output is correct
18 Correct 0 ms 344 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 352 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 241 ms 57704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 284 ms 69592 KB Output is correct
3 Correct 281 ms 69560 KB Output is correct
4 Correct 345 ms 69568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 284 ms 69592 KB Output is correct
3 Correct 281 ms 69560 KB Output is correct
4 Correct 345 ms 69568 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 286 ms 69736 KB Output is correct
7 Correct 270 ms 69788 KB Output is correct
8 Correct 276 ms 69820 KB Output is correct
9 Correct 301 ms 69824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 284 ms 69592 KB Output is correct
3 Correct 281 ms 69560 KB Output is correct
4 Correct 345 ms 69568 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 27 ms 7892 KB Output is correct
7 Correct 35 ms 7752 KB Output is correct
8 Correct 28 ms 7884 KB Output is correct
9 Correct 31 ms 7888 KB Output is correct
10 Correct 27 ms 7888 KB Output is correct
11 Correct 31 ms 7876 KB Output is correct
12 Correct 29 ms 7872 KB Output is correct
13 Correct 39 ms 7884 KB Output is correct
14 Correct 27 ms 7872 KB Output is correct
15 Correct 32 ms 7884 KB Output is correct
16 Correct 33 ms 8144 KB Output is correct
17 Correct 31 ms 7844 KB Output is correct
18 Correct 319 ms 69588 KB Output is correct
19 Correct 266 ms 69824 KB Output is correct
20 Correct 326 ms 69568 KB Output is correct
21 Correct 30 ms 7888 KB Output is correct
22 Correct 26 ms 7892 KB Output is correct
23 Correct 90 ms 26560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 30 ms 7896 KB Output is correct
3 Correct 31 ms 7888 KB Output is correct
4 Correct 302 ms 69740 KB Output is correct
5 Correct 36 ms 7884 KB Output is correct
6 Correct 37 ms 7888 KB Output is correct
7 Correct 33 ms 7888 KB Output is correct
8 Correct 32 ms 7840 KB Output is correct
9 Correct 30 ms 7796 KB Output is correct
10 Correct 30 ms 7812 KB Output is correct
11 Correct 37 ms 7884 KB Output is correct
12 Correct 36 ms 7880 KB Output is correct
13 Correct 37 ms 7792 KB Output is correct
14 Correct 299 ms 69828 KB Output is correct
15 Correct 29 ms 7888 KB Output is correct
16 Correct 286 ms 69648 KB Output is correct
17 Correct 270 ms 69728 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1232 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 464 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 1360 KB Output is correct
17 Correct 32 ms 7896 KB Output is correct
18 Correct 0 ms 344 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 352 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 356 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 241 ms 57704 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 284 ms 69592 KB Output is correct
31 Correct 281 ms 69560 KB Output is correct
32 Correct 345 ms 69568 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 286 ms 69736 KB Output is correct
35 Correct 270 ms 69788 KB Output is correct
36 Correct 276 ms 69820 KB Output is correct
37 Correct 301 ms 69824 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 27 ms 7892 KB Output is correct
40 Correct 35 ms 7752 KB Output is correct
41 Correct 28 ms 7884 KB Output is correct
42 Correct 31 ms 7888 KB Output is correct
43 Correct 27 ms 7888 KB Output is correct
44 Correct 31 ms 7876 KB Output is correct
45 Correct 29 ms 7872 KB Output is correct
46 Correct 39 ms 7884 KB Output is correct
47 Correct 27 ms 7872 KB Output is correct
48 Correct 32 ms 7884 KB Output is correct
49 Correct 33 ms 8144 KB Output is correct
50 Correct 31 ms 7844 KB Output is correct
51 Correct 319 ms 69588 KB Output is correct
52 Correct 266 ms 69824 KB Output is correct
53 Correct 326 ms 69568 KB Output is correct
54 Correct 30 ms 7888 KB Output is correct
55 Correct 26 ms 7892 KB Output is correct
56 Correct 90 ms 26560 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 30 ms 7896 KB Output is correct
59 Correct 31 ms 7888 KB Output is correct
60 Correct 302 ms 69740 KB Output is correct
61 Correct 36 ms 7884 KB Output is correct
62 Correct 37 ms 7888 KB Output is correct
63 Correct 33 ms 7888 KB Output is correct
64 Correct 32 ms 7840 KB Output is correct
65 Correct 30 ms 7796 KB Output is correct
66 Correct 30 ms 7812 KB Output is correct
67 Correct 37 ms 7884 KB Output is correct
68 Correct 36 ms 7880 KB Output is correct
69 Correct 37 ms 7792 KB Output is correct
70 Correct 299 ms 69828 KB Output is correct
71 Correct 29 ms 7888 KB Output is correct
72 Correct 286 ms 69648 KB Output is correct
73 Correct 270 ms 69728 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 3 ms 1372 KB Output is correct
80 Correct 303 ms 69712 KB Output is correct
81 Correct 306 ms 69648 KB Output is correct
82 Correct 328 ms 69824 KB Output is correct
83 Correct 295 ms 69568 KB Output is correct
84 Correct 308 ms 69568 KB Output is correct
85 Correct 300 ms 69688 KB Output is correct
86 Correct 83 ms 26568 KB Output is correct
87 Correct 0 ms 344 KB Output is correct