답안 #677268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677268 2023-01-02T17:15:01 Z amirhoseinfar1385 이상한 기계 (APIO19_strange_device) C++17
100 / 100
948 ms 65024 KB
#include<bits/stdc++.h>
using namespace std;
long long inf=1e18+10;

long long mul(long long a,long long b){
	if(inf/a<b){
		return inf;
	}
	else{
		long long ret=1ll*a*b;
		return ret;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n;
	long long a,b;
	cin>>n>>a>>b;
	long long e=mul(a/gcd(a,(b+1)),b);
	map<long long ,long long>mp;
	for(int i=0;i<n;i++){
		long long l,r;
		cin>>l>>r;
		if(r-l+1>=e){
			cout<<e<<"\n";
			return 0;
		}
		l%=e;
		r%=e;
	//	cout<<l<<" "<<r<<endl;
		mp[l]++;
		if(l>r){
			mp[e]--;
			mp[0]++;
		}
		mp[r+1]--;
	}
	long long last=0;
	for(auto x:mp){
		mp[x.first]+=last;
		last=mp[x.first];
	}
	long long res=0;
	long long ll=0,rr=0,f=0;
	for(auto x:mp){
		rr=x.first;
		if(x.second==0){
	//	    cout<<rr<<" "<<ll<<" "<<x.first<<endl;
			res+=rr-ll;
			ll=rr;
			f=0;
		}
		else{
			if(f==0){
				ll=x.first;
				f=1;
			}
		}
	}
	cout<<res<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 1236 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1236 KB Output is correct
17 Correct 82 ms 8140 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 328 KB Output is correct
5 Correct 239 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 749 ms 63036 KB Output is correct
3 Correct 796 ms 64668 KB Output is correct
4 Correct 948 ms 64724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 749 ms 63036 KB Output is correct
3 Correct 796 ms 64668 KB Output is correct
4 Correct 948 ms 64724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 783 ms 64832 KB Output is correct
7 Correct 869 ms 64884 KB Output is correct
8 Correct 793 ms 64872 KB Output is correct
9 Correct 943 ms 64724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 749 ms 63036 KB Output is correct
3 Correct 796 ms 64668 KB Output is correct
4 Correct 948 ms 64724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 70 ms 8204 KB Output is correct
7 Correct 78 ms 8312 KB Output is correct
8 Correct 69 ms 8196 KB Output is correct
9 Correct 85 ms 8284 KB Output is correct
10 Correct 65 ms 8268 KB Output is correct
11 Correct 65 ms 8272 KB Output is correct
12 Correct 69 ms 8244 KB Output is correct
13 Correct 83 ms 8292 KB Output is correct
14 Correct 78 ms 8236 KB Output is correct
15 Correct 83 ms 8276 KB Output is correct
16 Correct 85 ms 8252 KB Output is correct
17 Correct 84 ms 8208 KB Output is correct
18 Correct 789 ms 64772 KB Output is correct
19 Correct 857 ms 64824 KB Output is correct
20 Correct 921 ms 64748 KB Output is correct
21 Correct 70 ms 8276 KB Output is correct
22 Correct 69 ms 8200 KB Output is correct
23 Correct 109 ms 1976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 86 ms 7992 KB Output is correct
3 Correct 80 ms 8228 KB Output is correct
4 Correct 875 ms 64872 KB Output is correct
5 Correct 90 ms 8260 KB Output is correct
6 Correct 98 ms 8308 KB Output is correct
7 Correct 84 ms 8300 KB Output is correct
8 Correct 80 ms 8300 KB Output is correct
9 Correct 80 ms 8320 KB Output is correct
10 Correct 73 ms 8372 KB Output is correct
11 Correct 73 ms 8324 KB Output is correct
12 Correct 73 ms 8204 KB Output is correct
13 Correct 84 ms 8280 KB Output is correct
14 Correct 914 ms 64764 KB Output is correct
15 Correct 80 ms 8384 KB Output is correct
16 Correct 744 ms 64768 KB Output is correct
17 Correct 739 ms 64888 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 1236 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1236 KB Output is correct
17 Correct 82 ms 8140 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 239 ms 376 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 749 ms 63036 KB Output is correct
31 Correct 796 ms 64668 KB Output is correct
32 Correct 948 ms 64724 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 783 ms 64832 KB Output is correct
35 Correct 869 ms 64884 KB Output is correct
36 Correct 793 ms 64872 KB Output is correct
37 Correct 943 ms 64724 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 70 ms 8204 KB Output is correct
40 Correct 78 ms 8312 KB Output is correct
41 Correct 69 ms 8196 KB Output is correct
42 Correct 85 ms 8284 KB Output is correct
43 Correct 65 ms 8268 KB Output is correct
44 Correct 65 ms 8272 KB Output is correct
45 Correct 69 ms 8244 KB Output is correct
46 Correct 83 ms 8292 KB Output is correct
47 Correct 78 ms 8236 KB Output is correct
48 Correct 83 ms 8276 KB Output is correct
49 Correct 85 ms 8252 KB Output is correct
50 Correct 84 ms 8208 KB Output is correct
51 Correct 789 ms 64772 KB Output is correct
52 Correct 857 ms 64824 KB Output is correct
53 Correct 921 ms 64748 KB Output is correct
54 Correct 70 ms 8276 KB Output is correct
55 Correct 69 ms 8200 KB Output is correct
56 Correct 109 ms 1976 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 86 ms 7992 KB Output is correct
59 Correct 80 ms 8228 KB Output is correct
60 Correct 875 ms 64872 KB Output is correct
61 Correct 90 ms 8260 KB Output is correct
62 Correct 98 ms 8308 KB Output is correct
63 Correct 84 ms 8300 KB Output is correct
64 Correct 80 ms 8300 KB Output is correct
65 Correct 80 ms 8320 KB Output is correct
66 Correct 73 ms 8372 KB Output is correct
67 Correct 73 ms 8324 KB Output is correct
68 Correct 73 ms 8204 KB Output is correct
69 Correct 84 ms 8280 KB Output is correct
70 Correct 914 ms 64764 KB Output is correct
71 Correct 80 ms 8384 KB Output is correct
72 Correct 744 ms 64768 KB Output is correct
73 Correct 739 ms 64888 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 8 ms 1236 KB Output is correct
80 Correct 926 ms 64860 KB Output is correct
81 Correct 859 ms 64780 KB Output is correct
82 Correct 920 ms 64716 KB Output is correct
83 Correct 885 ms 64836 KB Output is correct
84 Correct 900 ms 65024 KB Output is correct
85 Correct 844 ms 64824 KB Output is correct
86 Correct 101 ms 1904 KB Output is correct
87 Correct 0 ms 212 KB Output is correct