Submission #258125

# Submission time Handle Problem Language Result Execution time Memory
258125 2020-08-05T11:54:36 Z amoo_safar Strange Device (APIO19_strange_device) C++17
100 / 100
742 ms 69168 KB
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef __int128 ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	long long n, A, B;
	cin >> n >> A >> B;
	ll z = A / __gcd(A, B + 1);
	ll L = z * B;
	vector<pll> V;

	long long l, r;
	for(int i = 0; i < n; i++){
		cin >> l >> r;
		if(r - l + 1 >= L) return cout << (long long)(L) << '\n', 0;
		if(l % L <= r % L) V.pb({l % L, r % L});
		else {
			V.pb({l % L, L - 1});
			V.pb({0,  r % L});
		}
	}
	sort(all(V));
	ll ans = L;
	ll la = -1;
	for(auto x : V){
		ans -= max(__int128(0), x.F - la - 1);
		la = max(la, x.S);
	}
	ans -= max(__int128(0), L - la - 1);

	cout << (long long)(ans) << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 67 ms 4588 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 416 ms 33268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 573 ms 33344 KB Output is correct
3 Correct 634 ms 33376 KB Output is correct
4 Correct 569 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 573 ms 33344 KB Output is correct
3 Correct 634 ms 33376 KB Output is correct
4 Correct 569 ms 33344 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 597 ms 33376 KB Output is correct
7 Correct 560 ms 33344 KB Output is correct
8 Correct 564 ms 33340 KB Output is correct
9 Correct 667 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 573 ms 33344 KB Output is correct
3 Correct 634 ms 33376 KB Output is correct
4 Correct 569 ms 33344 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 54 ms 4636 KB Output is correct
7 Correct 58 ms 4596 KB Output is correct
8 Correct 55 ms 4588 KB Output is correct
9 Correct 57 ms 4620 KB Output is correct
10 Correct 53 ms 4588 KB Output is correct
11 Correct 68 ms 4628 KB Output is correct
12 Correct 54 ms 4588 KB Output is correct
13 Correct 60 ms 4560 KB Output is correct
14 Correct 74 ms 4584 KB Output is correct
15 Correct 65 ms 4596 KB Output is correct
16 Correct 56 ms 4580 KB Output is correct
17 Correct 55 ms 4588 KB Output is correct
18 Correct 568 ms 33344 KB Output is correct
19 Correct 566 ms 33344 KB Output is correct
20 Correct 695 ms 33344 KB Output is correct
21 Correct 64 ms 4588 KB Output is correct
22 Correct 54 ms 4596 KB Output is correct
23 Correct 173 ms 16852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 57 ms 4588 KB Output is correct
3 Correct 66 ms 4592 KB Output is correct
4 Correct 728 ms 33464 KB Output is correct
5 Correct 60 ms 4584 KB Output is correct
6 Correct 57 ms 4588 KB Output is correct
7 Correct 60 ms 4584 KB Output is correct
8 Correct 60 ms 4588 KB Output is correct
9 Correct 59 ms 4588 KB Output is correct
10 Correct 59 ms 4584 KB Output is correct
11 Correct 59 ms 4588 KB Output is correct
12 Correct 56 ms 4588 KB Output is correct
13 Correct 56 ms 4584 KB Output is correct
14 Correct 638 ms 33348 KB Output is correct
15 Correct 56 ms 4588 KB Output is correct
16 Correct 563 ms 33332 KB Output is correct
17 Correct 541 ms 33344 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 67 ms 4588 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 416 ms 33268 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 573 ms 33344 KB Output is correct
31 Correct 634 ms 33376 KB Output is correct
32 Correct 569 ms 33344 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 597 ms 33376 KB Output is correct
35 Correct 560 ms 33344 KB Output is correct
36 Correct 564 ms 33340 KB Output is correct
37 Correct 667 ms 33344 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 54 ms 4636 KB Output is correct
40 Correct 58 ms 4596 KB Output is correct
41 Correct 55 ms 4588 KB Output is correct
42 Correct 57 ms 4620 KB Output is correct
43 Correct 53 ms 4588 KB Output is correct
44 Correct 68 ms 4628 KB Output is correct
45 Correct 54 ms 4588 KB Output is correct
46 Correct 60 ms 4560 KB Output is correct
47 Correct 74 ms 4584 KB Output is correct
48 Correct 65 ms 4596 KB Output is correct
49 Correct 56 ms 4580 KB Output is correct
50 Correct 55 ms 4588 KB Output is correct
51 Correct 568 ms 33344 KB Output is correct
52 Correct 566 ms 33344 KB Output is correct
53 Correct 695 ms 33344 KB Output is correct
54 Correct 64 ms 4588 KB Output is correct
55 Correct 54 ms 4596 KB Output is correct
56 Correct 173 ms 16852 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 57 ms 4588 KB Output is correct
59 Correct 66 ms 4592 KB Output is correct
60 Correct 728 ms 33464 KB Output is correct
61 Correct 60 ms 4584 KB Output is correct
62 Correct 57 ms 4588 KB Output is correct
63 Correct 60 ms 4584 KB Output is correct
64 Correct 60 ms 4588 KB Output is correct
65 Correct 59 ms 4588 KB Output is correct
66 Correct 59 ms 4584 KB Output is correct
67 Correct 59 ms 4588 KB Output is correct
68 Correct 56 ms 4588 KB Output is correct
69 Correct 56 ms 4584 KB Output is correct
70 Correct 638 ms 33348 KB Output is correct
71 Correct 56 ms 4588 KB Output is correct
72 Correct 563 ms 33332 KB Output is correct
73 Correct 541 ms 33344 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 6 ms 1408 KB Output is correct
80 Correct 712 ms 68940 KB Output is correct
81 Correct 742 ms 69148 KB Output is correct
82 Correct 705 ms 69020 KB Output is correct
83 Correct 678 ms 69004 KB Output is correct
84 Correct 659 ms 69024 KB Output is correct
85 Correct 637 ms 69168 KB Output is correct
86 Correct 185 ms 26708 KB Output is correct
87 Correct 0 ms 384 KB Output is correct