제출 #206607

#제출 시각아이디문제언어결과실행 시간메모리
206607kshitij_sodani이상한 기계 (APIO19_strange_device)C++17
100 / 100
652 ms63392 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long llo;
#define ak first
#define  bk second
#define endl "\n"
llo gcd(llo kk,llo ll){
	if(ll==0){
		return kk;
	}
	return gcd(ll,kk%ll);
}
const llo inf = (llo)1e18 + 3;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n,a,b;
	cin>>n>>a>>b;
	llo x;
	vector<pair<llo,llo>> it;
	x=b;
	llo y=a/gcd(a,b+1);
	/*if(y>1000000000000000000LL/b){

	}*/
	
/*	if((b+1)%a==0){
		x=b;
	}
	else{
		x=a*b;
	}*/


	llo aa,bb;
	llo ss=0;
	vector<pair<llo,llo>> ac;
	for(llo i=0;i<n;i++){
		cin>>aa>>bb;
		ss+=bb-aa+1;
		it.pb(mp(aa,bb));
	}
	if(y>(llo)2*(inf/b)){
		cout<<ss<<endl;
		return 0;
	}
	x*=(a/gcd(a,b+1));
	for(llo i=0;i<n;i++){
		aa=it[i].ak;
		bb=it[i].bk;
		if(bb-aa+1>=x){
			cout<<x<<endl;
			return 0;
		}
		/*if(bb-aa+1>=x){
			ac.pb(mp(0,x-1));
		}*/
		aa%=x;
		bb%=x;
		if(bb<aa){
			ac.pb(mp(aa,x-1));
			ac.pb(mp(0,bb));
		}
		else{
			ac.pb(mp(aa,bb));
		}

	}

/*	if(s==1){
		cout<<x<<endl;
	}
	else{*/
		vector<pair<llo,llo>> prev;
		sort(ac.begin(),ac.end());

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













	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

strange_device.cpp: In function 'int main()':
strange_device.cpp:95:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(llo i=0;i<prev.size();i++){
               ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...