Submission #977090

# Submission time Handle Problem Language Result Execution time Memory
977090 2024-05-07T11:23:23 Z dubabuba Strange Device (APIO19_strange_device) C++14
100 / 100
1211 ms 63200 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
 
#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 348 KB Output is correct
2 Correct 11 ms 860 KB Output is correct
3 Correct 11 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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 11 ms 860 KB Output is correct
17 Correct 131 ms 6492 KB Output is correct
18 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 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 1 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 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 708 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1104 ms 63072 KB Output is correct
3 Correct 1129 ms 63028 KB Output is correct
4 Correct 1144 ms 63088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1104 ms 63072 KB Output is correct
3 Correct 1129 ms 63028 KB Output is correct
4 Correct 1144 ms 63088 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1136 ms 62904 KB Output is correct
7 Correct 1122 ms 63008 KB Output is correct
8 Correct 1111 ms 62964 KB Output is correct
9 Correct 1139 ms 62860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1104 ms 63072 KB Output is correct
3 Correct 1129 ms 63028 KB Output is correct
4 Correct 1144 ms 63088 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 107 ms 6432 KB Output is correct
7 Correct 107 ms 6468 KB Output is correct
8 Correct 111 ms 6544 KB Output is correct
9 Correct 110 ms 6636 KB Output is correct
10 Correct 107 ms 6484 KB Output is correct
11 Correct 126 ms 6484 KB Output is correct
12 Correct 119 ms 6516 KB Output is correct
13 Correct 109 ms 6664 KB Output is correct
14 Correct 107 ms 6512 KB Output is correct
15 Correct 118 ms 6736 KB Output is correct
16 Correct 112 ms 6484 KB Output is correct
17 Correct 115 ms 6484 KB Output is correct
18 Correct 1123 ms 63148 KB Output is correct
19 Correct 1173 ms 63144 KB Output is correct
20 Correct 1145 ms 63152 KB Output is correct
21 Correct 114 ms 6484 KB Output is correct
22 Correct 110 ms 6484 KB Output is correct
23 Correct 310 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 116 ms 6584 KB Output is correct
3 Correct 115 ms 6656 KB Output is correct
4 Correct 1167 ms 62964 KB Output is correct
5 Correct 110 ms 6484 KB Output is correct
6 Correct 113 ms 6484 KB Output is correct
7 Correct 111 ms 6484 KB Output is correct
8 Correct 110 ms 6484 KB Output is correct
9 Correct 111 ms 6640 KB Output is correct
10 Correct 108 ms 6480 KB Output is correct
11 Correct 111 ms 6464 KB Output is correct
12 Correct 110 ms 6628 KB Output is correct
13 Correct 110 ms 6500 KB Output is correct
14 Correct 1176 ms 62912 KB Output is correct
15 Correct 107 ms 6484 KB Output is correct
16 Correct 1148 ms 63080 KB Output is correct
17 Correct 1120 ms 62904 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 11 ms 860 KB Output is correct
3 Correct 11 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 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 11 ms 860 KB Output is correct
17 Correct 131 ms 6492 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 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 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 708 ms 408 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1104 ms 63072 KB Output is correct
31 Correct 1129 ms 63028 KB Output is correct
32 Correct 1144 ms 63088 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1136 ms 62904 KB Output is correct
35 Correct 1122 ms 63008 KB Output is correct
36 Correct 1111 ms 62964 KB Output is correct
37 Correct 1139 ms 62860 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 107 ms 6432 KB Output is correct
40 Correct 107 ms 6468 KB Output is correct
41 Correct 111 ms 6544 KB Output is correct
42 Correct 110 ms 6636 KB Output is correct
43 Correct 107 ms 6484 KB Output is correct
44 Correct 126 ms 6484 KB Output is correct
45 Correct 119 ms 6516 KB Output is correct
46 Correct 109 ms 6664 KB Output is correct
47 Correct 107 ms 6512 KB Output is correct
48 Correct 118 ms 6736 KB Output is correct
49 Correct 112 ms 6484 KB Output is correct
50 Correct 115 ms 6484 KB Output is correct
51 Correct 1123 ms 63148 KB Output is correct
52 Correct 1173 ms 63144 KB Output is correct
53 Correct 1145 ms 63152 KB Output is correct
54 Correct 114 ms 6484 KB Output is correct
55 Correct 110 ms 6484 KB Output is correct
56 Correct 310 ms 408 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 116 ms 6584 KB Output is correct
59 Correct 115 ms 6656 KB Output is correct
60 Correct 1167 ms 62964 KB Output is correct
61 Correct 110 ms 6484 KB Output is correct
62 Correct 113 ms 6484 KB Output is correct
63 Correct 111 ms 6484 KB Output is correct
64 Correct 110 ms 6484 KB Output is correct
65 Correct 111 ms 6640 KB Output is correct
66 Correct 108 ms 6480 KB Output is correct
67 Correct 111 ms 6464 KB Output is correct
68 Correct 110 ms 6628 KB Output is correct
69 Correct 110 ms 6500 KB Output is correct
70 Correct 1176 ms 62912 KB Output is correct
71 Correct 107 ms 6484 KB Output is correct
72 Correct 1148 ms 63080 KB Output is correct
73 Correct 1120 ms 62904 KB Output is correct
74 Correct 0 ms 348 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 344 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 14 ms 968 KB Output is correct
80 Correct 1161 ms 62940 KB Output is correct
81 Correct 1148 ms 62948 KB Output is correct
82 Correct 1211 ms 62780 KB Output is correct
83 Correct 1144 ms 62824 KB Output is correct
84 Correct 1199 ms 62888 KB Output is correct
85 Correct 1141 ms 63200 KB Output is correct
86 Correct 315 ms 408 KB Output is correct
87 Correct 1 ms 344 KB Output is correct