Submission #154724

#TimeUsernameProblemLanguageResultExecution timeMemory
154724Pro_ktmr이상한 기계 (APIO19_strange_device)C++14
100 / 100
2745 ms17492 KiB
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair

LL gcd(LL a, LL b){
	if(a%b == 0) return b;
	return gcd(b, a%b);
}

int N;
LL A, B, S;
vector<pair<LL,LL>> all; //closed range

int main(){
	cin >> N >> A >> B;
	S = A*B/gcd(A, B+1);
	//cout << S << endl;
	for(int i=0; i<N; i++){
		LL l, r;
		cin >> l >> r;
		if(l/S == r/S){
			all.push_back(MP(l%S, r%S));
			//cout << l%S << " " << r%S << endl;
		}
		else if(l/S+1 == r/S){
			all.push_back(MP(l%S, S-1));
			all.push_back(MP(0, r%S));
			//cout << l%S << " " << S-1 << endl;
			//cout << 0 << " " << r%S << endl;
		}
		else{
			all.push_back(MP(0, S-1));
			//cout << 0 << " " << S-1 << endl;
		}
	}
	sort(all.begin(), all.end());
	for(int i=0; i<all.size()-1; i++){
		if(all[i+1].first <= all[i].second){
			all[i+1].first = all[i].first;
			all[i+1].second = max(all[i].second, all[i+1].second);
			all[i] = MP(-1,-2);
		}
	}
	LL ans = 0;
	for(int i=0; i<all.size(); i++){
		//cout << all[i].first << " " << all[i].second << " " << all[i].second - all[i].first + 1 << endl;
		ans += all[i].second - all[i].first + 1;
	}
	cout << ans << endl;
	
	return 0;
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<all.size()-1; i++){
               ~^~~~~~~~~~~~~
strange_device.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<all.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...