Submission #206593

# Submission time Handle Problem Language Result Execution time Memory
206593 2020-03-04T07:25:02 Z kshitij_sodani Strange Device (APIO19_strange_device) C++17
35 / 100
849 ms 81768 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){
			ac.insert(mp(0,x-1));
		}
		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:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(llo i=0;i<prev.size();i++){
               ~^~~~~~~~~~~~
strange_device.cpp:80: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 12 ms 1784 KB Output is correct
3 Correct 12 ms 1656 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 376 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 5 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 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1784 KB Output is correct
17 Correct 82 ms 10764 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 380 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 280 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 349 ms 2372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 770 ms 81488 KB Output is correct
3 Correct 801 ms 81360 KB Output is correct
4 Correct 824 ms 81616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 770 ms 81488 KB Output is correct
3 Correct 801 ms 81360 KB Output is correct
4 Correct 824 ms 81616 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 815 ms 81744 KB Output is correct
7 Correct 832 ms 81768 KB Output is correct
8 Correct 804 ms 81496 KB Output is correct
9 Correct 845 ms 81616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 770 ms 81488 KB Output is correct
3 Correct 801 ms 81360 KB Output is correct
4 Correct 824 ms 81616 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 77 ms 10776 KB Output is correct
7 Correct 80 ms 10732 KB Output is correct
8 Correct 82 ms 10728 KB Output is correct
9 Correct 90 ms 10732 KB Output is correct
10 Correct 80 ms 10728 KB Output is correct
11 Correct 81 ms 10732 KB Output is correct
12 Correct 78 ms 10732 KB Output is correct
13 Correct 84 ms 10732 KB Output is correct
14 Correct 78 ms 10728 KB Output is correct
15 Correct 92 ms 10744 KB Output is correct
16 Correct 81 ms 10728 KB Output is correct
17 Correct 81 ms 10732 KB Output is correct
18 Correct 798 ms 81488 KB Output is correct
19 Correct 814 ms 81592 KB Output is correct
20 Correct 845 ms 81488 KB Output is correct
21 Correct 83 ms 10924 KB Output is correct
22 Correct 84 ms 10728 KB Output is correct
23 Correct 153 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 87 ms 10728 KB Output is correct
3 Correct 85 ms 10728 KB Output is correct
4 Correct 823 ms 81576 KB Output is correct
5 Correct 94 ms 10856 KB Output is correct
6 Correct 89 ms 10732 KB Output is correct
7 Correct 90 ms 10732 KB Output is correct
8 Correct 81 ms 10728 KB Output is correct
9 Correct 86 ms 10736 KB Output is correct
10 Correct 82 ms 10728 KB Output is correct
11 Correct 83 ms 10732 KB Output is correct
12 Correct 85 ms 10860 KB Output is correct
13 Correct 89 ms 10728 KB Output is correct
14 Correct 849 ms 81500 KB Output is correct
15 Correct 80 ms 10728 KB Output is correct
16 Correct 800 ms 81488 KB Output is correct
17 Correct 785 ms 81616 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 12 ms 1784 KB Output is correct
3 Correct 12 ms 1656 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 376 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 5 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 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1784 KB Output is correct
17 Correct 82 ms 10764 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct