Submission #678146

# Submission time Handle Problem Language Result Execution time Memory
678146 2023-01-05T08:53:56 Z faribourz Strange Device (APIO19_strange_device) C++14
100 / 100
779 ms 67948 KB
// Only GOD
// believe in yourself
// Nemidam Del Be In Darde Donya!
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define bit(x, y) ((x >> y)&1)
#define sz(x) (int)x.size()
#define kill(x) return cout << x << '\n', void()
#define KILL(x) return cout << x << '\n', 0
#define int ll

const int INF = 1e18;
map<int, int> M;
int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int A, B, n;
	cin >> n >> A >> B;
	int g = __gcd(A, B+1);
	int AB;
	A /= g;
	if(INF / A < B+1){
		AB = INF;
	}
	else
		AB = A*B;
	int ans = 0;
	for(int i = 0; i < n; i++){
		int l, r;
		cin >> l >> r;
		if(r-l+1 >= AB)
			ans = AB;
		l %= AB, r %= AB;
		if(!r){
			M[0]++;
			M[1]--;
			if(l)
				M[l]++, M[AB]--;
			continue;
		}
		if(l <= r){
			M[l]++;
			M[r+1]--;
		}
		else{
			M[0]++;
			M[l]++;
			M[AB]--;
			M[r+1]--;
		}
	}
	if(ans)
		KILL(ans);
	int sum = 0, lst = -1;
	ans = 0;
	for(auto x : M){
		if(lst == -1){
			sum += x.S;
			lst = x.F;
			continue;
		}
		if(sum > 0){
			ans += x.F-lst;
		}
		sum += x.S;
		lst = x.F;
	}
	cout << min(ans, AB);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 11 ms 852 KB Output is correct
3 Correct 7 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 66 ms 10020 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 248 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 639 ms 62944 KB Output is correct
3 Correct 658 ms 66424 KB Output is correct
4 Correct 726 ms 67780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 639 ms 62944 KB Output is correct
3 Correct 658 ms 66424 KB Output is correct
4 Correct 726 ms 67780 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 714 ms 67948 KB Output is correct
7 Correct 700 ms 67916 KB Output is correct
8 Correct 664 ms 67932 KB Output is correct
9 Correct 713 ms 64716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 639 ms 62944 KB Output is correct
3 Correct 658 ms 66424 KB Output is correct
4 Correct 726 ms 67780 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 62 ms 10000 KB Output is correct
7 Correct 57 ms 10036 KB Output is correct
8 Correct 63 ms 10124 KB Output is correct
9 Correct 66 ms 10032 KB Output is correct
10 Correct 57 ms 10012 KB Output is correct
11 Correct 61 ms 10016 KB Output is correct
12 Correct 65 ms 10064 KB Output is correct
13 Correct 72 ms 10080 KB Output is correct
14 Correct 55 ms 10088 KB Output is correct
15 Correct 73 ms 10060 KB Output is correct
16 Correct 68 ms 10012 KB Output is correct
17 Correct 69 ms 10064 KB Output is correct
18 Correct 652 ms 64704 KB Output is correct
19 Correct 737 ms 67944 KB Output is correct
20 Correct 718 ms 64596 KB Output is correct
21 Correct 63 ms 10100 KB Output is correct
22 Correct 66 ms 10016 KB Output is correct
23 Correct 118 ms 3804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 69 ms 6576 KB Output is correct
3 Correct 70 ms 6524 KB Output is correct
4 Correct 779 ms 63016 KB Output is correct
5 Correct 100 ms 6552 KB Output is correct
6 Correct 67 ms 6484 KB Output is correct
7 Correct 66 ms 6540 KB Output is correct
8 Correct 68 ms 6544 KB Output is correct
9 Correct 68 ms 6556 KB Output is correct
10 Correct 62 ms 6580 KB Output is correct
11 Correct 61 ms 6476 KB Output is correct
12 Correct 69 ms 6568 KB Output is correct
13 Correct 77 ms 6496 KB Output is correct
14 Correct 740 ms 62880 KB Output is correct
15 Correct 58 ms 6476 KB Output is correct
16 Correct 707 ms 63036 KB Output is correct
17 Correct 679 ms 62920 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 11 ms 852 KB Output is correct
3 Correct 7 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 66 ms 10020 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 248 ms 300 KB Output is correct
29 Correct 1 ms 216 KB Output is correct
30 Correct 639 ms 62944 KB Output is correct
31 Correct 658 ms 66424 KB Output is correct
32 Correct 726 ms 67780 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 714 ms 67948 KB Output is correct
35 Correct 700 ms 67916 KB Output is correct
36 Correct 664 ms 67932 KB Output is correct
37 Correct 713 ms 64716 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 62 ms 10000 KB Output is correct
40 Correct 57 ms 10036 KB Output is correct
41 Correct 63 ms 10124 KB Output is correct
42 Correct 66 ms 10032 KB Output is correct
43 Correct 57 ms 10012 KB Output is correct
44 Correct 61 ms 10016 KB Output is correct
45 Correct 65 ms 10064 KB Output is correct
46 Correct 72 ms 10080 KB Output is correct
47 Correct 55 ms 10088 KB Output is correct
48 Correct 73 ms 10060 KB Output is correct
49 Correct 68 ms 10012 KB Output is correct
50 Correct 69 ms 10064 KB Output is correct
51 Correct 652 ms 64704 KB Output is correct
52 Correct 737 ms 67944 KB Output is correct
53 Correct 718 ms 64596 KB Output is correct
54 Correct 63 ms 10100 KB Output is correct
55 Correct 66 ms 10016 KB Output is correct
56 Correct 118 ms 3804 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 69 ms 6576 KB Output is correct
59 Correct 70 ms 6524 KB Output is correct
60 Correct 779 ms 63016 KB Output is correct
61 Correct 100 ms 6552 KB Output is correct
62 Correct 67 ms 6484 KB Output is correct
63 Correct 66 ms 6540 KB Output is correct
64 Correct 68 ms 6544 KB Output is correct
65 Correct 68 ms 6556 KB Output is correct
66 Correct 62 ms 6580 KB Output is correct
67 Correct 61 ms 6476 KB Output is correct
68 Correct 69 ms 6568 KB Output is correct
69 Correct 77 ms 6496 KB Output is correct
70 Correct 740 ms 62880 KB Output is correct
71 Correct 58 ms 6476 KB Output is correct
72 Correct 707 ms 63036 KB Output is correct
73 Correct 679 ms 62920 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 2 ms 212 KB Output is correct
78 Correct 1 ms 316 KB Output is correct
79 Correct 18 ms 1224 KB Output is correct
80 Correct 724 ms 64460 KB Output is correct
81 Correct 706 ms 64608 KB Output is correct
82 Correct 773 ms 64436 KB Output is correct
83 Correct 723 ms 64608 KB Output is correct
84 Correct 748 ms 64464 KB Output is correct
85 Correct 691 ms 65172 KB Output is correct
86 Correct 140 ms 1780 KB Output is correct
87 Correct 1 ms 212 KB Output is correct