답안 #206587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206587 2020-03-04T06:57:49 Z kshitij_sodani 이상한 기계 (APIO19_strange_device) C++17
35 / 100
852 ms 79824 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;
	set<pair<llo,llo>> ac;
	for(llo i=0;i<n;i++){
		cin>>aa>>bb;
		if(bb-aa>=x){
			cout<<x<<endl;
			return 0;
		}
		aa%=x;
		bb%=x;
		if(bb<aa){
			ac.insert(mp(aa,x-1));
			ac.insert(mp(0,bb));
		}
		else{
			ac.insert(mp(aa,bb));
		}

	}
	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;
	}
	cout<<tot<<endl;













	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:67:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(llo i=0;i<prev.size();i++){
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 12 ms 1400 KB Output is correct
3 Correct 13 ms 1356 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 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 4 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 87 ms 8808 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 347 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 819 ms 79568 KB Output is correct
3 Correct 781 ms 79568 KB Output is correct
4 Correct 824 ms 79632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 819 ms 79568 KB Output is correct
3 Correct 781 ms 79568 KB Output is correct
4 Correct 824 ms 79632 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 852 ms 79580 KB Output is correct
7 Correct 798 ms 79568 KB Output is correct
8 Correct 777 ms 79728 KB Output is correct
9 Correct 841 ms 79628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 819 ms 79568 KB Output is correct
3 Correct 781 ms 79568 KB Output is correct
4 Correct 824 ms 79632 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 76 ms 8896 KB Output is correct
7 Correct 84 ms 8808 KB Output is correct
8 Correct 80 ms 8812 KB Output is correct
9 Correct 84 ms 8812 KB Output is correct
10 Correct 75 ms 8812 KB Output is correct
11 Correct 83 ms 8972 KB Output is correct
12 Correct 80 ms 8812 KB Output is correct
13 Correct 88 ms 8812 KB Output is correct
14 Correct 79 ms 8808 KB Output is correct
15 Correct 98 ms 8936 KB Output is correct
16 Correct 83 ms 8812 KB Output is correct
17 Correct 77 ms 8808 KB Output is correct
18 Correct 783 ms 79568 KB Output is correct
19 Correct 808 ms 79568 KB Output is correct
20 Correct 839 ms 79568 KB Output is correct
21 Correct 78 ms 8808 KB Output is correct
22 Correct 79 ms 8812 KB Output is correct
23 Correct 153 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 87 ms 8808 KB Output is correct
3 Correct 81 ms 8812 KB Output is correct
4 Correct 807 ms 79620 KB Output is correct
5 Correct 83 ms 8812 KB Output is correct
6 Correct 88 ms 8808 KB Output is correct
7 Correct 88 ms 8812 KB Output is correct
8 Correct 80 ms 8808 KB Output is correct
9 Correct 84 ms 8812 KB Output is correct
10 Correct 79 ms 8736 KB Output is correct
11 Correct 80 ms 8812 KB Output is correct
12 Correct 83 ms 8912 KB Output is correct
13 Correct 83 ms 8812 KB Output is correct
14 Correct 814 ms 79568 KB Output is correct
15 Correct 80 ms 8808 KB Output is correct
16 Correct 786 ms 79824 KB Output is correct
17 Correct 790 ms 79568 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 12 ms 1400 KB Output is correct
3 Correct 13 ms 1356 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 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 4 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 87 ms 8808 KB Output is correct
18 Incorrect 5 ms 376 KB Output isn't correct