답안 #400066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400066 2021-05-07T09:49:27 Z juggernaut 이상한 기계 (APIO19_strange_device) C++17
100 / 100
542 ms 30400 KB
//Another code but understand that a*b/gcd(a,b+1) is all !!!!
#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:33:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 696 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 51 ms 2480 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 342 ms 29992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 466 ms 16832 KB Output is correct
3 Correct 456 ms 16804 KB Output is correct
4 Correct 454 ms 16828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 466 ms 16832 KB Output is correct
3 Correct 456 ms 16804 KB Output is correct
4 Correct 454 ms 16828 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 460 ms 16824 KB Output is correct
7 Correct 465 ms 30116 KB Output is correct
8 Correct 461 ms 30240 KB Output is correct
9 Correct 502 ms 30104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 466 ms 16832 KB Output is correct
3 Correct 456 ms 16804 KB Output is correct
4 Correct 454 ms 16828 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 44 ms 2472 KB Output is correct
7 Correct 49 ms 5664 KB Output is correct
8 Correct 46 ms 5744 KB Output is correct
9 Correct 47 ms 5720 KB Output is correct
10 Correct 45 ms 5724 KB Output is correct
11 Correct 49 ms 5624 KB Output is correct
12 Correct 45 ms 5728 KB Output is correct
13 Correct 53 ms 5800 KB Output is correct
14 Correct 45 ms 5692 KB Output is correct
15 Correct 51 ms 5732 KB Output is correct
16 Correct 50 ms 5664 KB Output is correct
17 Correct 57 ms 5688 KB Output is correct
18 Correct 470 ms 30224 KB Output is correct
19 Correct 446 ms 30116 KB Output is correct
20 Correct 511 ms 30116 KB Output is correct
21 Correct 49 ms 5692 KB Output is correct
22 Correct 43 ms 5640 KB Output is correct
23 Correct 148 ms 18720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 49 ms 2428 KB Output is correct
3 Correct 50 ms 5688 KB Output is correct
4 Correct 533 ms 30116 KB Output is correct
5 Correct 50 ms 5688 KB Output is correct
6 Correct 50 ms 5692 KB Output is correct
7 Correct 49 ms 5696 KB Output is correct
8 Correct 51 ms 5664 KB Output is correct
9 Correct 51 ms 5708 KB Output is correct
10 Correct 50 ms 5700 KB Output is correct
11 Correct 50 ms 5672 KB Output is correct
12 Correct 43 ms 5692 KB Output is correct
13 Correct 50 ms 5624 KB Output is correct
14 Correct 507 ms 30220 KB Output is correct
15 Correct 50 ms 5728 KB Output is correct
16 Correct 475 ms 30244 KB Output is correct
17 Correct 507 ms 30196 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 696 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 51 ms 2480 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 342 ms 29992 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 466 ms 16832 KB Output is correct
31 Correct 456 ms 16804 KB Output is correct
32 Correct 454 ms 16828 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 460 ms 16824 KB Output is correct
35 Correct 465 ms 30116 KB Output is correct
36 Correct 461 ms 30240 KB Output is correct
37 Correct 502 ms 30104 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 44 ms 2472 KB Output is correct
40 Correct 49 ms 5664 KB Output is correct
41 Correct 46 ms 5744 KB Output is correct
42 Correct 47 ms 5720 KB Output is correct
43 Correct 45 ms 5724 KB Output is correct
44 Correct 49 ms 5624 KB Output is correct
45 Correct 45 ms 5728 KB Output is correct
46 Correct 53 ms 5800 KB Output is correct
47 Correct 45 ms 5692 KB Output is correct
48 Correct 51 ms 5732 KB Output is correct
49 Correct 50 ms 5664 KB Output is correct
50 Correct 57 ms 5688 KB Output is correct
51 Correct 470 ms 30224 KB Output is correct
52 Correct 446 ms 30116 KB Output is correct
53 Correct 511 ms 30116 KB Output is correct
54 Correct 49 ms 5692 KB Output is correct
55 Correct 43 ms 5640 KB Output is correct
56 Correct 148 ms 18720 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 49 ms 2428 KB Output is correct
59 Correct 50 ms 5688 KB Output is correct
60 Correct 533 ms 30116 KB Output is correct
61 Correct 50 ms 5688 KB Output is correct
62 Correct 50 ms 5692 KB Output is correct
63 Correct 49 ms 5696 KB Output is correct
64 Correct 51 ms 5664 KB Output is correct
65 Correct 51 ms 5708 KB Output is correct
66 Correct 50 ms 5700 KB Output is correct
67 Correct 50 ms 5672 KB Output is correct
68 Correct 43 ms 5692 KB Output is correct
69 Correct 50 ms 5624 KB Output is correct
70 Correct 507 ms 30220 KB Output is correct
71 Correct 50 ms 5728 KB Output is correct
72 Correct 475 ms 30244 KB Output is correct
73 Correct 507 ms 30196 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 976 KB Output is correct
80 Correct 534 ms 30224 KB Output is correct
81 Correct 542 ms 30116 KB Output is correct
82 Correct 501 ms 30116 KB Output is correct
83 Correct 506 ms 30116 KB Output is correct
84 Correct 537 ms 30400 KB Output is correct
85 Correct 510 ms 30100 KB Output is correct
86 Correct 141 ms 18480 KB Output is correct
87 Correct 1 ms 204 KB Output is correct