답안 #298023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298023 2020-09-12T09:53:41 Z miss_robot 이상한 기계 (APIO19_strange_device) C++14
100 / 100
566 ms 65872 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#define int long long

using namespace std;

const int N = 1152921504606846976;
int sol, n, a, b, l, r, cycle, last = -1, tl;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin >> n >> a >> b;
	vector< pair<int, int> > qry, iv;
	while(n--){
		cin >> l >> r;
		qry.push_back({l, r});
	}
	int temp = __gcd(a, b+1);
	if((a/temp) <= N/b) cycle = (a/temp)*b;
	for(auto &t : qry){
		tie(l, r) = t;
		if(cycle && r-l+1 >= cycle){
			cout << cycle << "\n";
			return 0;
		}
		if(cycle) l %= cycle, r %= cycle;
		if(l <= r) iv.push_back({l, r});
		else iv.push_back({0, r}), iv.push_back({l, cycle-1});
	}
	sort(iv.begin(), iv.end());
	for(auto &t : iv){
		tie(l, r) = t;
		if(last == -1) tl = r, last = l;
		else if(tl < l){
			sol += tl-last+1;
			tl = r, last = l;
		}
		else tl = max(tl, r);
	}
	if(last != -1) sol += tl-last+1;
	cout << sol << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1296 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1280 KB Output is correct
17 Correct 55 ms 8680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 375 ms 65872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 480 ms 50572 KB Output is correct
3 Correct 478 ms 51008 KB Output is correct
4 Correct 487 ms 50752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 480 ms 50572 KB Output is correct
3 Correct 478 ms 51008 KB Output is correct
4 Correct 487 ms 50752 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 476 ms 50496 KB Output is correct
7 Correct 488 ms 55404 KB Output is correct
8 Correct 481 ms 55368 KB Output is correct
9 Correct 523 ms 55232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 480 ms 50572 KB Output is correct
3 Correct 478 ms 51008 KB Output is correct
4 Correct 487 ms 50752 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 49 ms 8680 KB Output is correct
7 Correct 52 ms 8684 KB Output is correct
8 Correct 59 ms 8680 KB Output is correct
9 Correct 50 ms 8680 KB Output is correct
10 Correct 50 ms 8680 KB Output is correct
11 Correct 50 ms 8680 KB Output is correct
12 Correct 48 ms 8680 KB Output is correct
13 Correct 53 ms 8684 KB Output is correct
14 Correct 49 ms 8684 KB Output is correct
15 Correct 54 ms 8680 KB Output is correct
16 Correct 54 ms 8688 KB Output is correct
17 Correct 49 ms 8684 KB Output is correct
18 Correct 486 ms 55232 KB Output is correct
19 Correct 470 ms 55364 KB Output is correct
20 Correct 528 ms 55232 KB Output is correct
21 Correct 51 ms 8676 KB Output is correct
22 Correct 46 ms 8684 KB Output is correct
23 Correct 161 ms 30548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 53 ms 8684 KB Output is correct
3 Correct 52 ms 8684 KB Output is correct
4 Correct 557 ms 50932 KB Output is correct
5 Correct 51 ms 8680 KB Output is correct
6 Correct 52 ms 8684 KB Output is correct
7 Correct 52 ms 8684 KB Output is correct
8 Correct 53 ms 8812 KB Output is correct
9 Correct 53 ms 8680 KB Output is correct
10 Correct 52 ms 8948 KB Output is correct
11 Correct 53 ms 8684 KB Output is correct
12 Correct 51 ms 8660 KB Output is correct
13 Correct 52 ms 8684 KB Output is correct
14 Correct 543 ms 50756 KB Output is correct
15 Correct 51 ms 8680 KB Output is correct
16 Correct 478 ms 50684 KB Output is correct
17 Correct 478 ms 50624 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1296 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1280 KB Output is correct
17 Correct 55 ms 8680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 375 ms 65872 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 480 ms 50572 KB Output is correct
31 Correct 478 ms 51008 KB Output is correct
32 Correct 487 ms 50752 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 476 ms 50496 KB Output is correct
35 Correct 488 ms 55404 KB Output is correct
36 Correct 481 ms 55368 KB Output is correct
37 Correct 523 ms 55232 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 49 ms 8680 KB Output is correct
40 Correct 52 ms 8684 KB Output is correct
41 Correct 59 ms 8680 KB Output is correct
42 Correct 50 ms 8680 KB Output is correct
43 Correct 50 ms 8680 KB Output is correct
44 Correct 50 ms 8680 KB Output is correct
45 Correct 48 ms 8680 KB Output is correct
46 Correct 53 ms 8684 KB Output is correct
47 Correct 49 ms 8684 KB Output is correct
48 Correct 54 ms 8680 KB Output is correct
49 Correct 54 ms 8688 KB Output is correct
50 Correct 49 ms 8684 KB Output is correct
51 Correct 486 ms 55232 KB Output is correct
52 Correct 470 ms 55364 KB Output is correct
53 Correct 528 ms 55232 KB Output is correct
54 Correct 51 ms 8676 KB Output is correct
55 Correct 46 ms 8684 KB Output is correct
56 Correct 161 ms 30548 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 53 ms 8684 KB Output is correct
59 Correct 52 ms 8684 KB Output is correct
60 Correct 557 ms 50932 KB Output is correct
61 Correct 51 ms 8680 KB Output is correct
62 Correct 52 ms 8684 KB Output is correct
63 Correct 52 ms 8684 KB Output is correct
64 Correct 53 ms 8812 KB Output is correct
65 Correct 53 ms 8680 KB Output is correct
66 Correct 52 ms 8948 KB Output is correct
67 Correct 53 ms 8684 KB Output is correct
68 Correct 51 ms 8660 KB Output is correct
69 Correct 52 ms 8684 KB Output is correct
70 Correct 543 ms 50756 KB Output is correct
71 Correct 51 ms 8680 KB Output is correct
72 Correct 478 ms 50684 KB Output is correct
73 Correct 478 ms 50624 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 5 ms 1280 KB Output is correct
80 Correct 561 ms 55312 KB Output is correct
81 Correct 566 ms 55488 KB Output is correct
82 Correct 523 ms 55556 KB Output is correct
83 Correct 528 ms 55280 KB Output is correct
84 Correct 535 ms 55232 KB Output is correct
85 Correct 532 ms 55380 KB Output is correct
86 Correct 157 ms 30540 KB Output is correct
87 Correct 1 ms 384 KB Output is correct