Submission #1086857

# Submission time Handle Problem Language Result Execution time Memory
1086857 2024-09-11T15:31:46 Z Jawad_Akbar_JJ Strange Device (APIO19_strange_device) C++17
100 / 100
1014 ms 53292 KB
#include <iostream>
#include <vector>

#include <algorithm>

using namespace std;
#define ll long long
#define i28 __int128

int main(){
	ll n, A, B;
	cin>>n>>A>>B;

	i28 k = A / __gcd(A, B + 1);
	k = k * B;

	vector<pair<ll, ll>> vec;

	for (int i=1;i<=n;i++){
		ll l, r;
		cin>>l>>r;

		if (r - l + 1 >= k){
			cout<<(long long)k<<'\n';
			return 0;
		}
		l = l % k;
		r = r % k;

		if (l <= r)
			vec.push_back({l, r});
		else{
			vec.push_back({l, k - 1});
			vec.push_back({0, r});
		}
	}

	sort(begin(vec), end(vec));

	ll mx = -1, ans = 0;

	for (auto [i, j] : vec){
		mx = max(mx, i - 1);
		ans += max(0LL, j - mx);
		mx = max(mx, j);
	}
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 1116 KB Output is correct
3 Correct 10 ms 1052 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 344 KB Output is correct
12 Correct 1 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 432 KB Output is correct
16 Correct 11 ms 1112 KB Output is correct
17 Correct 99 ms 5728 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 660 ms 41152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 912 ms 53140 KB Output is correct
3 Correct 910 ms 53140 KB Output is correct
4 Correct 913 ms 53188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 912 ms 53140 KB Output is correct
3 Correct 910 ms 53140 KB Output is correct
4 Correct 913 ms 53188 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 904 ms 53244 KB Output is correct
7 Correct 959 ms 53252 KB Output is correct
8 Correct 883 ms 53288 KB Output is correct
9 Correct 938 ms 53140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 912 ms 53140 KB Output is correct
3 Correct 910 ms 53140 KB Output is correct
4 Correct 913 ms 53188 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 88 ms 5576 KB Output is correct
7 Correct 92 ms 5768 KB Output is correct
8 Correct 93 ms 5820 KB Output is correct
9 Correct 92 ms 5824 KB Output is correct
10 Correct 91 ms 5820 KB Output is correct
11 Correct 94 ms 5608 KB Output is correct
12 Correct 92 ms 5820 KB Output is correct
13 Correct 93 ms 5820 KB Output is correct
14 Correct 95 ms 5816 KB Output is correct
15 Correct 103 ms 5824 KB Output is correct
16 Correct 94 ms 5568 KB Output is correct
17 Correct 94 ms 5820 KB Output is correct
18 Correct 935 ms 53204 KB Output is correct
19 Correct 965 ms 53140 KB Output is correct
20 Correct 971 ms 53196 KB Output is correct
21 Correct 95 ms 5572 KB Output is correct
22 Correct 93 ms 5572 KB Output is correct
23 Correct 324 ms 18356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 98 ms 5676 KB Output is correct
3 Correct 97 ms 5820 KB Output is correct
4 Correct 959 ms 53148 KB Output is correct
5 Correct 97 ms 5620 KB Output is correct
6 Correct 94 ms 5716 KB Output is correct
7 Correct 101 ms 5820 KB Output is correct
8 Correct 96 ms 5820 KB Output is correct
9 Correct 95 ms 5820 KB Output is correct
10 Correct 98 ms 5824 KB Output is correct
11 Correct 97 ms 5664 KB Output is correct
12 Correct 91 ms 5712 KB Output is correct
13 Correct 94 ms 5776 KB Output is correct
14 Correct 965 ms 53140 KB Output is correct
15 Correct 94 ms 5820 KB Output is correct
16 Correct 957 ms 53144 KB Output is correct
17 Correct 934 ms 53140 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 1116 KB Output is correct
3 Correct 10 ms 1052 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 344 KB Output is correct
12 Correct 1 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 432 KB Output is correct
16 Correct 11 ms 1112 KB Output is correct
17 Correct 99 ms 5728 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 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 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 660 ms 41152 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 912 ms 53140 KB Output is correct
31 Correct 910 ms 53140 KB Output is correct
32 Correct 913 ms 53188 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 904 ms 53244 KB Output is correct
35 Correct 959 ms 53252 KB Output is correct
36 Correct 883 ms 53288 KB Output is correct
37 Correct 938 ms 53140 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 88 ms 5576 KB Output is correct
40 Correct 92 ms 5768 KB Output is correct
41 Correct 93 ms 5820 KB Output is correct
42 Correct 92 ms 5824 KB Output is correct
43 Correct 91 ms 5820 KB Output is correct
44 Correct 94 ms 5608 KB Output is correct
45 Correct 92 ms 5820 KB Output is correct
46 Correct 93 ms 5820 KB Output is correct
47 Correct 95 ms 5816 KB Output is correct
48 Correct 103 ms 5824 KB Output is correct
49 Correct 94 ms 5568 KB Output is correct
50 Correct 94 ms 5820 KB Output is correct
51 Correct 935 ms 53204 KB Output is correct
52 Correct 965 ms 53140 KB Output is correct
53 Correct 971 ms 53196 KB Output is correct
54 Correct 95 ms 5572 KB Output is correct
55 Correct 93 ms 5572 KB Output is correct
56 Correct 324 ms 18356 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 98 ms 5676 KB Output is correct
59 Correct 97 ms 5820 KB Output is correct
60 Correct 959 ms 53148 KB Output is correct
61 Correct 97 ms 5620 KB Output is correct
62 Correct 94 ms 5716 KB Output is correct
63 Correct 101 ms 5820 KB Output is correct
64 Correct 96 ms 5820 KB Output is correct
65 Correct 95 ms 5820 KB Output is correct
66 Correct 98 ms 5824 KB Output is correct
67 Correct 97 ms 5664 KB Output is correct
68 Correct 91 ms 5712 KB Output is correct
69 Correct 94 ms 5776 KB Output is correct
70 Correct 965 ms 53140 KB Output is correct
71 Correct 94 ms 5820 KB Output is correct
72 Correct 957 ms 53144 KB Output is correct
73 Correct 934 ms 53140 KB Output is correct
74 Correct 1 ms 600 KB Output is correct
75 Correct 1 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 10 ms 1116 KB Output is correct
80 Correct 998 ms 53144 KB Output is correct
81 Correct 1014 ms 53140 KB Output is correct
82 Correct 949 ms 53144 KB Output is correct
83 Correct 978 ms 53228 KB Output is correct
84 Correct 955 ms 53292 KB Output is correct
85 Correct 956 ms 53136 KB Output is correct
86 Correct 299 ms 18568 KB Output is correct
87 Correct 0 ms 344 KB Output is correct