Submission #977089

# Submission time Handle Problem Language Result Execution time Memory
977089 2024-05-07T11:22:06 Z dubabuba Strange Device (APIO19_strange_device) C++14
100 / 100
1427 ms 99036 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
 
int gcd(int a, int b) {
	if(a == 0) return b;
	if(b == 0) return a;
	return gcd(b % a, a);
}
 
signed main() {
	int a, b, n, t;
	cin >> n >> a >> b;
	int d = gcd(a, b + 1);

	double sda = 1.0  * a / d * b;
	if(sda <= 1e18) t = a / d * b;
	else t = 1e18;
	set<pii> v;
 
	int l, r; bool gay = false;
	for(int i = 0; i < n; i++) {
		cin >> l >> r;
		if(r - l + 1 >= t) {
			gay = 1;
			continue;
		}
 
		l %= t;
		r %= t;
 
		if(l <= r) {
			// root->upt(l, r);
			v.insert(MP(l, r));
		}
		else {
			// root->upt(l, t - 1);
			// root->upt(0, r);
			v.insert(MP(l, t - 1));
			v.insert(MP(0, r));
		}
	}
 
	if(gay) {
		cout << t << endl;
		// if(t == (int) 1e18)
			// return 1;
		return 0;
	}

	v.insert(MP(2e18, 2e18));
 
	int ans = 0;
	l = (*v.begin()).ff, r = l;
	for(pii p : v) {
		if(r < p.ff) {
			ans += (r - l + 1);
			l = p.ff;
			r = p.ss;
		}
		r = max(r, p.ss);
	}

	if(ans < 0) return 1;
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1112 KB Output is correct
3 Correct 12 ms 860 KB Output is correct
4 Correct 1 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 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 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 1 ms 344 KB Output is correct
16 Correct 11 ms 860 KB Output is correct
17 Correct 110 ms 6592 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 1 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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 670 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1099 ms 63092 KB Output is correct
3 Correct 1133 ms 62984 KB Output is correct
4 Correct 1132 ms 62840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1099 ms 63092 KB Output is correct
3 Correct 1133 ms 62984 KB Output is correct
4 Correct 1132 ms 62840 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1133 ms 62912 KB Output is correct
7 Correct 1114 ms 62976 KB Output is correct
8 Correct 1117 ms 62904 KB Output is correct
9 Correct 1155 ms 63268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1099 ms 63092 KB Output is correct
3 Correct 1133 ms 62984 KB Output is correct
4 Correct 1132 ms 62840 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 105 ms 6652 KB Output is correct
7 Correct 107 ms 6480 KB Output is correct
8 Correct 108 ms 6644 KB Output is correct
9 Correct 126 ms 6788 KB Output is correct
10 Correct 107 ms 6484 KB Output is correct
11 Correct 107 ms 6460 KB Output is correct
12 Correct 107 ms 6564 KB Output is correct
13 Correct 109 ms 6592 KB Output is correct
14 Correct 112 ms 10244 KB Output is correct
15 Correct 120 ms 10284 KB Output is correct
16 Correct 138 ms 10228 KB Output is correct
17 Correct 112 ms 10668 KB Output is correct
18 Correct 1156 ms 98704 KB Output is correct
19 Correct 1140 ms 98808 KB Output is correct
20 Correct 1160 ms 99036 KB Output is correct
21 Correct 110 ms 10324 KB Output is correct
22 Correct 108 ms 10172 KB Output is correct
23 Correct 336 ms 12820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 129 ms 6448 KB Output is correct
3 Correct 112 ms 6448 KB Output is correct
4 Correct 1137 ms 98676 KB Output is correct
5 Correct 113 ms 10320 KB Output is correct
6 Correct 111 ms 10288 KB Output is correct
7 Correct 111 ms 10208 KB Output is correct
8 Correct 140 ms 10296 KB Output is correct
9 Correct 111 ms 10320 KB Output is correct
10 Correct 108 ms 10260 KB Output is correct
11 Correct 110 ms 10324 KB Output is correct
12 Correct 116 ms 10192 KB Output is correct
13 Correct 124 ms 10412 KB Output is correct
14 Correct 1178 ms 98760 KB Output is correct
15 Correct 109 ms 10320 KB Output is correct
16 Correct 1147 ms 98788 KB Output is correct
17 Correct 1177 ms 98876 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1112 KB Output is correct
3 Correct 12 ms 860 KB Output is correct
4 Correct 1 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 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 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 1 ms 344 KB Output is correct
16 Correct 11 ms 860 KB Output is correct
17 Correct 110 ms 6592 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 1 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 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 670 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1099 ms 63092 KB Output is correct
31 Correct 1133 ms 62984 KB Output is correct
32 Correct 1132 ms 62840 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1133 ms 62912 KB Output is correct
35 Correct 1114 ms 62976 KB Output is correct
36 Correct 1117 ms 62904 KB Output is correct
37 Correct 1155 ms 63268 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 105 ms 6652 KB Output is correct
40 Correct 107 ms 6480 KB Output is correct
41 Correct 108 ms 6644 KB Output is correct
42 Correct 126 ms 6788 KB Output is correct
43 Correct 107 ms 6484 KB Output is correct
44 Correct 107 ms 6460 KB Output is correct
45 Correct 107 ms 6564 KB Output is correct
46 Correct 109 ms 6592 KB Output is correct
47 Correct 112 ms 10244 KB Output is correct
48 Correct 120 ms 10284 KB Output is correct
49 Correct 138 ms 10228 KB Output is correct
50 Correct 112 ms 10668 KB Output is correct
51 Correct 1156 ms 98704 KB Output is correct
52 Correct 1140 ms 98808 KB Output is correct
53 Correct 1160 ms 99036 KB Output is correct
54 Correct 110 ms 10324 KB Output is correct
55 Correct 108 ms 10172 KB Output is correct
56 Correct 336 ms 12820 KB Output is correct
57 Correct 0 ms 600 KB Output is correct
58 Correct 129 ms 6448 KB Output is correct
59 Correct 112 ms 6448 KB Output is correct
60 Correct 1137 ms 98676 KB Output is correct
61 Correct 113 ms 10320 KB Output is correct
62 Correct 111 ms 10288 KB Output is correct
63 Correct 111 ms 10208 KB Output is correct
64 Correct 140 ms 10296 KB Output is correct
65 Correct 111 ms 10320 KB Output is correct
66 Correct 108 ms 10260 KB Output is correct
67 Correct 110 ms 10324 KB Output is correct
68 Correct 116 ms 10192 KB Output is correct
69 Correct 124 ms 10412 KB Output is correct
70 Correct 1178 ms 98760 KB Output is correct
71 Correct 109 ms 10320 KB Output is correct
72 Correct 1147 ms 98788 KB Output is correct
73 Correct 1177 ms 98876 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 11 ms 1216 KB Output is correct
80 Correct 1153 ms 98624 KB Output is correct
81 Correct 1427 ms 98564 KB Output is correct
82 Correct 1179 ms 98764 KB Output is correct
83 Correct 1173 ms 98624 KB Output is correct
84 Correct 1217 ms 98524 KB Output is correct
85 Correct 1216 ms 98532 KB Output is correct
86 Correct 311 ms 12668 KB Output is correct
87 Correct 1 ms 348 KB Output is correct