Submission #283291

# Submission time Handle Problem Language Result Execution time Memory
283291 2020-08-25T13:50:27 Z groeneprof Strange Device (APIO19_strange_device) C++14
100 / 100
768 ms 35544 KB
#include <bits/stdc++.h>
#define int long long
#define P(a) do{if(debug) cout<<a<<endl;} while(false)
#define H(a) P(#a<<": "<<a)
#define FR(i,a,b) for(int i = (a); i<(b); i++)
#define F(i,n) FR(i,0,n)

const int debug = 1;

using namespace std;
int n, A, B;
int p;

int ggd(int a, int b){
	if(a<b) swap(a,b);
	while(b!=0){
		a = a%b;
		swap(a,b);
	}
	return a;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>A>>B;
	p = (A/ggd(A,B+1));
	if(((int)sqrt(p))*((int)sqrt(B))>1e9){
		p = 2e18;
	}
	else p *= B;
	vector<pair<int,int> > segments;
	F(i,n){
		int l,r;
		cin>>l>>r;
		if(r-l+1>=p){
			cout<<p<<endl;
			return 0;
		}
		l%=p;
		r%=p;
		if(r >= l){
			segments.push_back({l,1});
			segments.push_back({r+1,-1});
		}
		else{
			segments.push_back({0,1});
			segments.push_back({r+1,-1});
			segments.push_back({l,1});
			segments.push_back({p,-1});
		}
	}
	sort(segments.begin(),segments.end());
	int cnt = segments[0].second;
	int ans = 0;
	FR(i,1,segments.size()){
		if(cnt>0){
			ans += segments[i].first-segments[i-1].first;
		}
		cnt += segments[i].second;
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:5:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FR(i,a,b) for(int i = (a); i<(b); i++)
      |                                     ^
strange_device.cpp:56:2: note: in expansion of macro 'FR'
   56 |  FR(i,1,segments.size()){
      |  ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 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 1 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 1 ms 384 KB Output is correct
16 Correct 8 ms 1408 KB Output is correct
17 Correct 74 ms 7440 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 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 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 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 437 ms 34368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 628 ms 35520 KB Output is correct
3 Correct 612 ms 35388 KB Output is correct
4 Correct 597 ms 35392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 628 ms 35520 KB Output is correct
3 Correct 612 ms 35388 KB Output is correct
4 Correct 597 ms 35392 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 596 ms 35460 KB Output is correct
7 Correct 563 ms 35544 KB Output is correct
8 Correct 578 ms 35392 KB Output is correct
9 Correct 676 ms 35504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 628 ms 35520 KB Output is correct
3 Correct 612 ms 35388 KB Output is correct
4 Correct 597 ms 35392 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 58 ms 7352 KB Output is correct
7 Correct 60 ms 7284 KB Output is correct
8 Correct 56 ms 7276 KB Output is correct
9 Correct 57 ms 7276 KB Output is correct
10 Correct 55 ms 7276 KB Output is correct
11 Correct 58 ms 7296 KB Output is correct
12 Correct 54 ms 7392 KB Output is correct
13 Correct 62 ms 7280 KB Output is correct
14 Correct 57 ms 7276 KB Output is correct
15 Correct 68 ms 7276 KB Output is correct
16 Correct 63 ms 7284 KB Output is correct
17 Correct 57 ms 7276 KB Output is correct
18 Correct 608 ms 35392 KB Output is correct
19 Correct 560 ms 35520 KB Output is correct
20 Correct 744 ms 35368 KB Output is correct
21 Correct 66 ms 7272 KB Output is correct
22 Correct 55 ms 7396 KB Output is correct
23 Correct 171 ms 25044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 65 ms 7272 KB Output is correct
3 Correct 73 ms 7344 KB Output is correct
4 Correct 768 ms 35392 KB Output is correct
5 Correct 64 ms 7276 KB Output is correct
6 Correct 63 ms 7284 KB Output is correct
7 Correct 65 ms 7276 KB Output is correct
8 Correct 68 ms 7272 KB Output is correct
9 Correct 63 ms 7272 KB Output is correct
10 Correct 68 ms 7392 KB Output is correct
11 Correct 63 ms 7284 KB Output is correct
12 Correct 59 ms 7276 KB Output is correct
13 Correct 76 ms 7516 KB Output is correct
14 Correct 695 ms 35388 KB Output is correct
15 Correct 68 ms 7276 KB Output is correct
16 Correct 554 ms 35392 KB Output is correct
17 Correct 570 ms 35392 KB Output is correct
18 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 6 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 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 1 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 1 ms 384 KB Output is correct
16 Correct 8 ms 1408 KB Output is correct
17 Correct 74 ms 7440 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 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 437 ms 34368 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 628 ms 35520 KB Output is correct
31 Correct 612 ms 35388 KB Output is correct
32 Correct 597 ms 35392 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 596 ms 35460 KB Output is correct
35 Correct 563 ms 35544 KB Output is correct
36 Correct 578 ms 35392 KB Output is correct
37 Correct 676 ms 35504 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 58 ms 7352 KB Output is correct
40 Correct 60 ms 7284 KB Output is correct
41 Correct 56 ms 7276 KB Output is correct
42 Correct 57 ms 7276 KB Output is correct
43 Correct 55 ms 7276 KB Output is correct
44 Correct 58 ms 7296 KB Output is correct
45 Correct 54 ms 7392 KB Output is correct
46 Correct 62 ms 7280 KB Output is correct
47 Correct 57 ms 7276 KB Output is correct
48 Correct 68 ms 7276 KB Output is correct
49 Correct 63 ms 7284 KB Output is correct
50 Correct 57 ms 7276 KB Output is correct
51 Correct 608 ms 35392 KB Output is correct
52 Correct 560 ms 35520 KB Output is correct
53 Correct 744 ms 35368 KB Output is correct
54 Correct 66 ms 7272 KB Output is correct
55 Correct 55 ms 7396 KB Output is correct
56 Correct 171 ms 25044 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 65 ms 7272 KB Output is correct
59 Correct 73 ms 7344 KB Output is correct
60 Correct 768 ms 35392 KB Output is correct
61 Correct 64 ms 7276 KB Output is correct
62 Correct 63 ms 7284 KB Output is correct
63 Correct 65 ms 7276 KB Output is correct
64 Correct 68 ms 7272 KB Output is correct
65 Correct 63 ms 7272 KB Output is correct
66 Correct 68 ms 7392 KB Output is correct
67 Correct 63 ms 7284 KB Output is correct
68 Correct 59 ms 7276 KB Output is correct
69 Correct 76 ms 7516 KB Output is correct
70 Correct 695 ms 35388 KB Output is correct
71 Correct 68 ms 7276 KB Output is correct
72 Correct 554 ms 35392 KB Output is correct
73 Correct 570 ms 35392 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 1 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 724 ms 35264 KB Output is correct
81 Correct 741 ms 35264 KB Output is correct
82 Correct 703 ms 35264 KB Output is correct
83 Correct 696 ms 35264 KB Output is correct
84 Correct 698 ms 35136 KB Output is correct
85 Correct 687 ms 35304 KB Output is correct
86 Correct 164 ms 26708 KB Output is correct
87 Correct 1 ms 384 KB Output is correct