Submission #1035200

# Submission time Handle Problem Language Result Execution time Memory
1035200 2024-07-26T06:25:07 Z Halym2007 Strange Device (APIO19_strange_device) C++17
100 / 100
340 ms 69828 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define sz size()
#define pii pair <ll, ll>
const int N = 1e7 + 5;
#define ll long long
#define pb push_back
vector <pii> v;
ll n, a, b, l[N], r[N];
int main () {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> a >> b;
	__int128 m = (__int128)a / __gcd (a, b + 1) * b;
	
	for (int i = 1; i <= n; ++i) {
		cin >> l[i] >> r[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (r[i] - l[i] + 1 >= m) {
			v.pb ({0, m - 1});
			continue;
		}
		if (l[i] % m > r[i] % m) {
			v.pb ({l[i] % m, m - 1});
			v.pb ({0, r[i] % m});
		}
		else {
			v.pb ({l[i] % m, r[i] % m});
		}
	}
	sort (v.begin(), v.end());
	ll l1 = v[0].ff, r1 = v[0].ss, jogap = 0;
	for (int i = 1; i < (int)v.sz; ++i) {
		if (v[i].ff <= r1) r1 = max (r1, v[i].ss);
		else if (v[i].ff > r1) {
			jogap += r1 - l1 + 1;
			l1 = v[i].ff; 
			r1 = v[i].ss;
		}
	}
	jogap += r1 - l1 + 1;
	cout << jogap;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1368 KB Output is correct
3 Correct 4 ms 1364 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 344 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 1372 KB Output is correct
17 Correct 30 ms 7884 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 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 1 ms 532 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 206 ms 57944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 277 ms 69572 KB Output is correct
3 Correct 289 ms 69824 KB Output is correct
4 Correct 270 ms 69732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 277 ms 69572 KB Output is correct
3 Correct 289 ms 69824 KB Output is correct
4 Correct 270 ms 69732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 287 ms 69628 KB Output is correct
7 Correct 319 ms 69572 KB Output is correct
8 Correct 286 ms 69668 KB Output is correct
9 Correct 283 ms 69552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 277 ms 69572 KB Output is correct
3 Correct 289 ms 69824 KB Output is correct
4 Correct 270 ms 69732 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 28 ms 7864 KB Output is correct
7 Correct 29 ms 7772 KB Output is correct
8 Correct 27 ms 7792 KB Output is correct
9 Correct 28 ms 7884 KB Output is correct
10 Correct 27 ms 7896 KB Output is correct
11 Correct 28 ms 7896 KB Output is correct
12 Correct 27 ms 7940 KB Output is correct
13 Correct 31 ms 7824 KB Output is correct
14 Correct 27 ms 7928 KB Output is correct
15 Correct 30 ms 7888 KB Output is correct
16 Correct 29 ms 7884 KB Output is correct
17 Correct 31 ms 7884 KB Output is correct
18 Correct 265 ms 69568 KB Output is correct
19 Correct 274 ms 69572 KB Output is correct
20 Correct 290 ms 69712 KB Output is correct
21 Correct 29 ms 7888 KB Output is correct
22 Correct 26 ms 7768 KB Output is correct
23 Correct 83 ms 26712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 30 ms 7928 KB Output is correct
3 Correct 30 ms 7896 KB Output is correct
4 Correct 340 ms 69716 KB Output is correct
5 Correct 29 ms 7888 KB Output is correct
6 Correct 31 ms 7888 KB Output is correct
7 Correct 29 ms 7888 KB Output is correct
8 Correct 30 ms 7772 KB Output is correct
9 Correct 29 ms 7884 KB Output is correct
10 Correct 29 ms 7896 KB Output is correct
11 Correct 29 ms 7832 KB Output is correct
12 Correct 27 ms 7888 KB Output is correct
13 Correct 30 ms 7884 KB Output is correct
14 Correct 285 ms 69764 KB Output is correct
15 Correct 29 ms 7888 KB Output is correct
16 Correct 284 ms 69764 KB Output is correct
17 Correct 260 ms 69572 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1368 KB Output is correct
3 Correct 4 ms 1364 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 344 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 1372 KB Output is correct
17 Correct 30 ms 7884 KB Output is correct
18 Correct 1 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 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 1 ms 532 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 206 ms 57944 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 277 ms 69572 KB Output is correct
31 Correct 289 ms 69824 KB Output is correct
32 Correct 270 ms 69732 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 287 ms 69628 KB Output is correct
35 Correct 319 ms 69572 KB Output is correct
36 Correct 286 ms 69668 KB Output is correct
37 Correct 283 ms 69552 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 28 ms 7864 KB Output is correct
40 Correct 29 ms 7772 KB Output is correct
41 Correct 27 ms 7792 KB Output is correct
42 Correct 28 ms 7884 KB Output is correct
43 Correct 27 ms 7896 KB Output is correct
44 Correct 28 ms 7896 KB Output is correct
45 Correct 27 ms 7940 KB Output is correct
46 Correct 31 ms 7824 KB Output is correct
47 Correct 27 ms 7928 KB Output is correct
48 Correct 30 ms 7888 KB Output is correct
49 Correct 29 ms 7884 KB Output is correct
50 Correct 31 ms 7884 KB Output is correct
51 Correct 265 ms 69568 KB Output is correct
52 Correct 274 ms 69572 KB Output is correct
53 Correct 290 ms 69712 KB Output is correct
54 Correct 29 ms 7888 KB Output is correct
55 Correct 26 ms 7768 KB Output is correct
56 Correct 83 ms 26712 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 30 ms 7928 KB Output is correct
59 Correct 30 ms 7896 KB Output is correct
60 Correct 340 ms 69716 KB Output is correct
61 Correct 29 ms 7888 KB Output is correct
62 Correct 31 ms 7888 KB Output is correct
63 Correct 29 ms 7888 KB Output is correct
64 Correct 30 ms 7772 KB Output is correct
65 Correct 29 ms 7884 KB Output is correct
66 Correct 29 ms 7896 KB Output is correct
67 Correct 29 ms 7832 KB Output is correct
68 Correct 27 ms 7888 KB Output is correct
69 Correct 30 ms 7884 KB Output is correct
70 Correct 285 ms 69764 KB Output is correct
71 Correct 29 ms 7888 KB Output is correct
72 Correct 284 ms 69764 KB Output is correct
73 Correct 260 ms 69572 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 3 ms 1372 KB Output is correct
80 Correct 295 ms 69648 KB Output is correct
81 Correct 297 ms 69568 KB Output is correct
82 Correct 290 ms 69584 KB Output is correct
83 Correct 295 ms 69744 KB Output is correct
84 Correct 296 ms 69828 KB Output is correct
85 Correct 285 ms 69568 KB Output is correct
86 Correct 82 ms 26568 KB Output is correct
87 Correct 0 ms 344 KB Output is correct