Submission #206591

# Submission time Handle Problem Language Result Execution time Memory
206591 2020-03-04T07:08:33 Z kshitij_sodani Strange Device (APIO19_strange_device) C++17
35 / 100
858 ms 79788 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define  b second
#define endl "\n"
llo gcd(llo kk,llo ll){
	if(ll==0){
		return kk;
	}
	return gcd(ll,kk%ll);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n,a,b;
	cin>>n>>a>>b;
	llo x;
	pair<llo,llo> it;
	x=b;
	x*=(a/gcd(a,b+1));
/*	if((b+1)%a==0){
		x=b;
	}
	else{
		x=a*b;
	}*/


	llo aa,bb;
	llo s=0;
	set<pair<llo,llo>> ac;
	for(llo i=0;i<n;i++){
		cin>>aa>>bb;
		/*if(bb-aa+1>=x){
			cout<<x<<endl;
			return 0;
		}*/
		if(bb-aa+1>=x){
			s=1;
			break;
		}
		aa%=x;
		bb%=x;
		if(bb<aa){
			ac.insert(mp(aa,x-1));
			ac.insert(mp(0,bb));
		}
		else{
			ac.insert(mp(aa,bb));
		}

	}
	if(s==1){
		cout<<x<<endl;
	}
	else{
		vector<pair<llo,llo>> prev;
		for(auto cc:ac){
			if(prev.size()==0){
				prev.pb(cc);
			}
			else{
				if(cc.a>prev.back().b){
					prev.pb(cc);
				}
				else{
					prev[prev.size()-1].b=max(prev[prev.size()-1].b,cc.b);
				}
			}
		}
		llo tot=0;
		for(llo i=0;i<prev.size();i++){
			tot+=prev[i].b-prev[i].a+1;
		}
		if(s==1 and tot<x){
			while(true){
				int y=1;
			}
		}

		cout<<tot<<endl;
	}













	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:76:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(llo i=0;i<prev.size();i++){
               ~^~~~~~~~~~~~
strange_device.cpp:81:9: warning: unused variable 'y' [-Wunused-variable]
     int y=1;
         ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 1400 KB Output is correct
3 Correct 12 ms 1400 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 12 ms 1404 KB Output is correct
17 Correct 84 ms 8808 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 358 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 794 ms 79696 KB Output is correct
3 Correct 832 ms 79568 KB Output is correct
4 Correct 819 ms 79572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 794 ms 79696 KB Output is correct
3 Correct 832 ms 79568 KB Output is correct
4 Correct 819 ms 79572 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 801 ms 79672 KB Output is correct
7 Correct 818 ms 79568 KB Output is correct
8 Correct 800 ms 79568 KB Output is correct
9 Correct 855 ms 79568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 794 ms 79696 KB Output is correct
3 Correct 832 ms 79568 KB Output is correct
4 Correct 819 ms 79572 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 78 ms 8752 KB Output is correct
7 Correct 82 ms 8808 KB Output is correct
8 Correct 81 ms 8800 KB Output is correct
9 Correct 85 ms 8808 KB Output is correct
10 Correct 78 ms 8788 KB Output is correct
11 Correct 77 ms 8812 KB Output is correct
12 Correct 78 ms 8808 KB Output is correct
13 Correct 85 ms 8808 KB Output is correct
14 Correct 76 ms 8816 KB Output is correct
15 Correct 87 ms 8812 KB Output is correct
16 Correct 85 ms 8812 KB Output is correct
17 Correct 79 ms 8808 KB Output is correct
18 Correct 808 ms 79696 KB Output is correct
19 Correct 810 ms 79768 KB Output is correct
20 Correct 858 ms 79568 KB Output is correct
21 Correct 88 ms 8812 KB Output is correct
22 Correct 91 ms 8812 KB Output is correct
23 Correct 166 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 84 ms 8808 KB Output is correct
3 Correct 84 ms 8812 KB Output is correct
4 Correct 823 ms 79788 KB Output is correct
5 Correct 85 ms 8812 KB Output is correct
6 Correct 89 ms 8812 KB Output is correct
7 Correct 88 ms 8808 KB Output is correct
8 Correct 83 ms 8812 KB Output is correct
9 Correct 86 ms 8808 KB Output is correct
10 Correct 83 ms 8816 KB Output is correct
11 Correct 81 ms 8812 KB Output is correct
12 Correct 80 ms 8812 KB Output is correct
13 Correct 86 ms 8812 KB Output is correct
14 Correct 831 ms 79700 KB Output is correct
15 Correct 84 ms 8812 KB Output is correct
16 Correct 811 ms 79696 KB Output is correct
17 Correct 769 ms 79568 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 1400 KB Output is correct
3 Correct 12 ms 1400 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 12 ms 1404 KB Output is correct
17 Correct 84 ms 8808 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct