답안 #171642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171642 2019-12-29T13:07:02 Z maximath_1 이상한 기계 (APIO19_strange_device) C++11
100 / 100
794 ms 35340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18+69;
vector<pair<int, int> >seg;
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, a, b;
	cin>>n>>a>>b;
	int gcd=__gcd(a, b+1);
	int t;
	if(a/gcd>inf/b) t=inf; //a*b/gcd>inf
	else t=(a/gcd)*b;
	for(int i=0; i<n; i++){
		int l, r; cin>>l>>r;
		if(r-l+1>=t) seg.push_back({0, t-1});
		else{
			l%=t; r%=t;
			if(l<=r) seg.push_back({l, r});
			else{
				seg.push_back({l, t-1});
				seg.push_back({0, r});
			}
		}
	}
	sort(seg.begin(), seg.end());
	int ans=0;
	for(int i=0; i<(int)seg.size(); i++){
		int l=seg[i].first, r=seg[i].second;
		int nxt=i;
		while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
			r=max(r, seg[nxt+1].second); nxt++;
		}
		ans+=r-l+1; i=nxt;
	}
	cout<<ans<<endl; return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:32:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 68 ms 5736 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 454 ms 25600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 619 ms 35340 KB Output is correct
3 Correct 622 ms 28244 KB Output is correct
4 Correct 607 ms 25932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 619 ms 35340 KB Output is correct
3 Correct 622 ms 28244 KB Output is correct
4 Correct 607 ms 25932 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 611 ms 26708 KB Output is correct
7 Correct 639 ms 29268 KB Output is correct
8 Correct 630 ms 29396 KB Output is correct
9 Correct 711 ms 34240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 619 ms 35340 KB Output is correct
3 Correct 622 ms 28244 KB Output is correct
4 Correct 607 ms 25932 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 61 ms 5740 KB Output is correct
7 Correct 66 ms 5836 KB Output is correct
8 Correct 62 ms 5736 KB Output is correct
9 Correct 66 ms 5824 KB Output is correct
10 Correct 61 ms 5736 KB Output is correct
11 Correct 65 ms 5844 KB Output is correct
12 Correct 61 ms 5800 KB Output is correct
13 Correct 68 ms 5984 KB Output is correct
14 Correct 61 ms 5892 KB Output is correct
15 Correct 69 ms 5708 KB Output is correct
16 Correct 71 ms 5736 KB Output is correct
17 Correct 64 ms 5808 KB Output is correct
18 Correct 723 ms 34076 KB Output is correct
19 Correct 611 ms 34084 KB Output is correct
20 Correct 676 ms 34124 KB Output is correct
21 Correct 67 ms 5736 KB Output is correct
22 Correct 61 ms 5904 KB Output is correct
23 Correct 194 ms 18500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 69 ms 3056 KB Output is correct
3 Correct 74 ms 5776 KB Output is correct
4 Correct 722 ms 29908 KB Output is correct
5 Correct 68 ms 5740 KB Output is correct
6 Correct 67 ms 5736 KB Output is correct
7 Correct 67 ms 5740 KB Output is correct
8 Correct 68 ms 5736 KB Output is correct
9 Correct 67 ms 5696 KB Output is correct
10 Correct 67 ms 5736 KB Output is correct
11 Correct 67 ms 5708 KB Output is correct
12 Correct 61 ms 5736 KB Output is correct
13 Correct 67 ms 5868 KB Output is correct
14 Correct 794 ms 33900 KB Output is correct
15 Correct 66 ms 5740 KB Output is correct
16 Correct 609 ms 33768 KB Output is correct
17 Correct 601 ms 29652 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 8 ms 1144 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 68 ms 5736 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 454 ms 25600 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 619 ms 35340 KB Output is correct
31 Correct 622 ms 28244 KB Output is correct
32 Correct 607 ms 25932 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 611 ms 26708 KB Output is correct
35 Correct 639 ms 29268 KB Output is correct
36 Correct 630 ms 29396 KB Output is correct
37 Correct 711 ms 34240 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 61 ms 5740 KB Output is correct
40 Correct 66 ms 5836 KB Output is correct
41 Correct 62 ms 5736 KB Output is correct
42 Correct 66 ms 5824 KB Output is correct
43 Correct 61 ms 5736 KB Output is correct
44 Correct 65 ms 5844 KB Output is correct
45 Correct 61 ms 5800 KB Output is correct
46 Correct 68 ms 5984 KB Output is correct
47 Correct 61 ms 5892 KB Output is correct
48 Correct 69 ms 5708 KB Output is correct
49 Correct 71 ms 5736 KB Output is correct
50 Correct 64 ms 5808 KB Output is correct
51 Correct 723 ms 34076 KB Output is correct
52 Correct 611 ms 34084 KB Output is correct
53 Correct 676 ms 34124 KB Output is correct
54 Correct 67 ms 5736 KB Output is correct
55 Correct 61 ms 5904 KB Output is correct
56 Correct 194 ms 18500 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 69 ms 3056 KB Output is correct
59 Correct 74 ms 5776 KB Output is correct
60 Correct 722 ms 29908 KB Output is correct
61 Correct 68 ms 5740 KB Output is correct
62 Correct 67 ms 5736 KB Output is correct
63 Correct 67 ms 5740 KB Output is correct
64 Correct 68 ms 5736 KB Output is correct
65 Correct 67 ms 5696 KB Output is correct
66 Correct 67 ms 5736 KB Output is correct
67 Correct 67 ms 5708 KB Output is correct
68 Correct 61 ms 5736 KB Output is correct
69 Correct 67 ms 5868 KB Output is correct
70 Correct 794 ms 33900 KB Output is correct
71 Correct 66 ms 5740 KB Output is correct
72 Correct 609 ms 33768 KB Output is correct
73 Correct 601 ms 29652 KB Output is correct
74 Correct 2 ms 380 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 1144 KB Output is correct
80 Correct 689 ms 31324 KB Output is correct
81 Correct 686 ms 31320 KB Output is correct
82 Correct 673 ms 31292 KB Output is correct
83 Correct 665 ms 31328 KB Output is correct
84 Correct 673 ms 31316 KB Output is correct
85 Correct 675 ms 31316 KB Output is correct
86 Correct 198 ms 18528 KB Output is correct
87 Correct 2 ms 376 KB Output is correct