Submission #172104

# Submission time Handle Problem Language Result Execution time Memory
172104 2019-12-31T06:36:49 Z super_j6 Strange Device (APIO19_strange_device) C++14
50 / 100
840 ms 53176 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<long long, long long>

const long long inf = 200000000000000000;
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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 888 KB Output is correct
3 Correct 9 ms 888 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 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 8 ms 888 KB Output is correct
17 Correct 65 ms 3960 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 439 ms 16888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 594 ms 17820 KB Output is correct
3 Correct 587 ms 17784 KB Output is correct
4 Correct 597 ms 28068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 594 ms 17820 KB Output is correct
3 Correct 587 ms 17784 KB Output is correct
4 Correct 597 ms 28068 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 594 ms 45464 KB Output is correct
7 Correct 604 ms 53112 KB Output is correct
8 Correct 596 ms 53112 KB Output is correct
9 Correct 840 ms 53176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 594 ms 17820 KB Output is correct
3 Correct 587 ms 17784 KB Output is correct
4 Correct 597 ms 28068 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 5664 KB Output is correct
8 Correct 59 ms 5624 KB Output is correct
9 Incorrect 63 ms 5624 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 66 ms 4976 KB Output is correct
3 Correct 63 ms 4092 KB Output is correct
4 Correct 672 ms 30632 KB Output is correct
5 Correct 64 ms 4088 KB Output is correct
6 Correct 64 ms 4088 KB Output is correct
7 Correct 64 ms 4088 KB Output is correct
8 Correct 65 ms 4088 KB Output is correct
9 Correct 63 ms 4216 KB Output is correct
10 Correct 63 ms 4088 KB Output is correct
11 Correct 63 ms 4068 KB Output is correct
12 Correct 57 ms 4088 KB Output is correct
13 Correct 64 ms 4036 KB Output is correct
14 Correct 644 ms 23924 KB Output is correct
15 Correct 63 ms 4060 KB Output is correct
16 Correct 592 ms 53020 KB Output is correct
17 Correct 580 ms 52656 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 888 KB Output is correct
3 Correct 9 ms 888 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 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 8 ms 888 KB Output is correct
17 Correct 65 ms 3960 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 8 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 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 439 ms 16888 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 594 ms 17820 KB Output is correct
31 Correct 587 ms 17784 KB Output is correct
32 Correct 597 ms 28068 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 594 ms 45464 KB Output is correct
35 Correct 604 ms 53112 KB Output is correct
36 Correct 596 ms 53112 KB Output is correct
37 Correct 840 ms 53176 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 5664 KB Output is correct
41 Correct 59 ms 5624 KB Output is correct
42 Incorrect 63 ms 5624 KB Output isn't correct
43 Halted 0 ms 0 KB -