Submission #283285

# Submission time Handle Problem Language Result Execution time Memory
283285 2020-08-25T13:37:12 Z groeneprof Strange Device (APIO19_strange_device) C++14
35 / 100
756 ms 35168 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;
	}
	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 1536 KB Output is correct
4 Correct 0 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 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 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 6 ms 1408 KB Output is correct
17 Correct 68 ms 7436 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't 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 Incorrect 1 ms 384 KB Output isn't 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 404 ms 34136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 572 ms 34880 KB Output is correct
3 Correct 599 ms 34880 KB Output is correct
4 Correct 570 ms 35040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 572 ms 34880 KB Output is correct
3 Correct 599 ms 34880 KB Output is correct
4 Correct 570 ms 35040 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 587 ms 34864 KB Output is correct
7 Correct 587 ms 34880 KB Output is correct
8 Correct 570 ms 34880 KB Output is correct
9 Correct 698 ms 35040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 572 ms 34880 KB Output is correct
3 Correct 599 ms 34880 KB Output is correct
4 Correct 570 ms 35040 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 60 ms 7384 KB Output is correct
7 Correct 60 ms 7276 KB Output is correct
8 Correct 66 ms 7424 KB Output is correct
9 Correct 58 ms 7312 KB Output is correct
10 Correct 54 ms 7276 KB Output is correct
11 Correct 58 ms 7432 KB Output is correct
12 Correct 56 ms 7380 KB Output is correct
13 Correct 62 ms 7284 KB Output is correct
14 Correct 55 ms 7272 KB Output is correct
15 Correct 66 ms 7276 KB Output is correct
16 Correct 63 ms 7284 KB Output is correct
17 Correct 58 ms 7372 KB Output is correct
18 Correct 592 ms 34880 KB Output is correct
19 Correct 546 ms 34888 KB Output is correct
20 Correct 725 ms 35024 KB Output is correct
21 Correct 71 ms 7276 KB Output is correct
22 Correct 54 ms 7396 KB Output is correct
23 Correct 164 ms 26708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 63 ms 7276 KB Output is correct
3 Correct 66 ms 7392 KB Output is correct
4 Correct 756 ms 35168 KB Output is correct
5 Correct 62 ms 7276 KB Output is correct
6 Correct 72 ms 7272 KB Output is correct
7 Correct 67 ms 7284 KB Output is correct
8 Correct 67 ms 7276 KB Output is correct
9 Correct 61 ms 7272 KB Output is correct
10 Correct 70 ms 7396 KB Output is correct
11 Correct 69 ms 7276 KB Output is correct
12 Correct 63 ms 7272 KB Output is correct
13 Correct 76 ms 7440 KB Output is correct
14 Correct 689 ms 34896 KB Output is correct
15 Correct 73 ms 7372 KB Output is correct
16 Correct 548 ms 34816 KB Output is correct
17 Correct 577 ms 34872 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't 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 1536 KB Output is correct
4 Correct 0 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 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 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 6 ms 1408 KB Output is correct
17 Correct 68 ms 7436 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct