답안 #172105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172105 2019-12-31T06:39:52 Z super_j6 이상한 기계 (APIO19_strange_device) C++14
100 / 100
802 ms 53304 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<long long, long long>

const long long inf = 2000000000000000000;
const int maxn = 2000001;
long long n, m, a, b;
pi p[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> a >> b;
	m = __gcd(b + 1, a) % a;
	m += a * (m == 0);
	m = min(inf / b, a / m) * b;
	
	for(int i = 0; i < n; i++){
		cin >> p[i].first >> p[i].second;
		if(p[i].second - p[i].first >= m) p[i] = {0, m - 1};
		p[i].first %= m, p[i].second %= m;
		if(p[i].second < p[i].first){
			p[i + 1] = {p[i].first, m - 1};
			p[i].first = 0;
			i++, n++;
		}
	} 
	
	p[n] = {m, m};
	sort(p, p + n);
	
	long long ret = 0;
	for(long long i = 0, j = p[0].second, k = p[0].first; i < n; i++){
		j = max(j, p[i].second);
		if(j < p[i + 1].first){
			ret += j - k + 1;
			k = p[i + 1].first;
		}
	}
	
	cout << ret << endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 632 KB Output is correct
3 Correct 8 ms 632 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 348 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 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 7 ms 632 KB Output is correct
17 Correct 65 ms 2040 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 380 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 2 ms 376 KB Output is correct
5 Correct 438 ms 16092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 592 ms 16980 KB Output is correct
3 Correct 597 ms 16996 KB Output is correct
4 Correct 603 ms 19052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 592 ms 16980 KB Output is correct
3 Correct 597 ms 16996 KB Output is correct
4 Correct 603 ms 19052 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 586 ms 17656 KB Output is correct
7 Correct 589 ms 18608 KB Output is correct
8 Correct 577 ms 18936 KB Output is correct
9 Correct 640 ms 18964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 592 ms 16980 KB Output is correct
3 Correct 597 ms 16996 KB Output is correct
4 Correct 603 ms 19052 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 58 ms 5624 KB Output is correct
7 Correct 62 ms 5624 KB Output is correct
8 Correct 59 ms 5624 KB Output is correct
9 Correct 61 ms 4768 KB Output is correct
10 Correct 59 ms 5628 KB Output is correct
11 Correct 65 ms 5688 KB Output is correct
12 Correct 60 ms 5752 KB Output is correct
13 Correct 65 ms 5624 KB Output is correct
14 Correct 58 ms 5624 KB Output is correct
15 Correct 65 ms 5628 KB Output is correct
16 Correct 69 ms 5624 KB Output is correct
17 Correct 61 ms 5624 KB Output is correct
18 Correct 596 ms 53040 KB Output is correct
19 Correct 584 ms 53304 KB Output is correct
20 Correct 644 ms 52928 KB Output is correct
21 Correct 64 ms 5624 KB Output is correct
22 Correct 58 ms 5548 KB Output is correct
23 Correct 186 ms 18176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 64 ms 3400 KB Output is correct
3 Correct 64 ms 2104 KB Output is correct
4 Correct 659 ms 19448 KB Output is correct
5 Correct 63 ms 2040 KB Output is correct
6 Correct 66 ms 3120 KB Output is correct
7 Correct 65 ms 3600 KB Output is correct
8 Correct 64 ms 1912 KB Output is correct
9 Correct 62 ms 2956 KB Output is correct
10 Correct 64 ms 1920 KB Output is correct
11 Correct 63 ms 2808 KB Output is correct
12 Correct 58 ms 4092 KB Output is correct
13 Correct 71 ms 4020 KB Output is correct
14 Correct 639 ms 23032 KB Output is correct
15 Correct 63 ms 4088 KB Output is correct
16 Correct 802 ms 21852 KB Output is correct
17 Correct 574 ms 21596 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 7 ms 632 KB Output is correct
3 Correct 8 ms 632 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 348 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 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 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 7 ms 632 KB Output is correct
17 Correct 65 ms 2040 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 380 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 2 ms 376 KB Output is correct
28 Correct 438 ms 16092 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 592 ms 16980 KB Output is correct
31 Correct 597 ms 16996 KB Output is correct
32 Correct 603 ms 19052 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 586 ms 17656 KB Output is correct
35 Correct 589 ms 18608 KB Output is correct
36 Correct 577 ms 18936 KB Output is correct
37 Correct 640 ms 18964 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 58 ms 5624 KB Output is correct
40 Correct 62 ms 5624 KB Output is correct
41 Correct 59 ms 5624 KB Output is correct
42 Correct 61 ms 4768 KB Output is correct
43 Correct 59 ms 5628 KB Output is correct
44 Correct 65 ms 5688 KB Output is correct
45 Correct 60 ms 5752 KB Output is correct
46 Correct 65 ms 5624 KB Output is correct
47 Correct 58 ms 5624 KB Output is correct
48 Correct 65 ms 5628 KB Output is correct
49 Correct 69 ms 5624 KB Output is correct
50 Correct 61 ms 5624 KB Output is correct
51 Correct 596 ms 53040 KB Output is correct
52 Correct 584 ms 53304 KB Output is correct
53 Correct 644 ms 52928 KB Output is correct
54 Correct 64 ms 5624 KB Output is correct
55 Correct 58 ms 5548 KB Output is correct
56 Correct 186 ms 18176 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 64 ms 3400 KB Output is correct
59 Correct 64 ms 2104 KB Output is correct
60 Correct 659 ms 19448 KB Output is correct
61 Correct 63 ms 2040 KB Output is correct
62 Correct 66 ms 3120 KB Output is correct
63 Correct 65 ms 3600 KB Output is correct
64 Correct 64 ms 1912 KB Output is correct
65 Correct 62 ms 2956 KB Output is correct
66 Correct 64 ms 1920 KB Output is correct
67 Correct 63 ms 2808 KB Output is correct
68 Correct 58 ms 4092 KB Output is correct
69 Correct 71 ms 4020 KB Output is correct
70 Correct 639 ms 23032 KB Output is correct
71 Correct 63 ms 4088 KB Output is correct
72 Correct 802 ms 21852 KB Output is correct
73 Correct 574 ms 21596 KB Output is correct
74 Correct 2 ms 376 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 416 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 888 KB Output is correct
80 Correct 671 ms 31492 KB Output is correct
81 Correct 680 ms 30980 KB Output is correct
82 Correct 643 ms 31348 KB Output is correct
83 Correct 637 ms 31148 KB Output is correct
84 Correct 643 ms 31420 KB Output is correct
85 Correct 639 ms 31508 KB Output is correct
86 Correct 184 ms 18112 KB Output is correct
87 Correct 2 ms 376 KB Output is correct