Submission #166416

# Submission time Handle Problem Language Result Execution time Memory
166416 2019-12-02T09:56:23 Z Feeder Strange Device (APIO19_strange_device) C++11
100 / 100
817 ms 53628 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	vector<pair<ll, ll> > vec;
	ll l, r, a, b, d, m, l2, r2, out = 0;
	cin >> n >> a >> b;
	d = a / __gcd(a, b+ 1);
	if(1e18 / b <= d) m = 1e18;
	else m = b * d;
	for(int i=0; i<n; i++){
		cin >> l >> r;
		l2 = r2 = -1;
		if(r / m == l / m) r %= m, l %= m;
		else if(r / m == l / m + 1){
			if(r % m + 1 >= l % m) l = 0, r = m - 1;
			else{
				l %= m, r %= m;
				l2 = 0, r2 = r;
				r = m - 1;
			}
		}
		else l = 0, r = m - 1;
		vec.emplace_back(l, r);
		if(l2 != -1) vec.emplace_back(l2, r2);
	}
	sort(vec.begin(), vec.end());
	l = r = -1;
	for(int i=0; i<vec.size(); i++){
		tie(a, b) = vec[i];
		if(a > r){
			l = a, r = b;
			out += (b - a + 1);
		}
		else if(b > r){
			out += (b - r);
			r = b;
		}			
	}
	cout << out;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vec.size(); i++){
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 21 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 10 ms 508 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 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 13 ms 1148 KB Output is correct
17 Correct 70 ms 6016 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 2 ms 380 KB Output is correct
3 Correct 1 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 0 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 470 ms 41388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 637 ms 53368 KB Output is correct
3 Correct 624 ms 53464 KB Output is correct
4 Correct 638 ms 53504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 637 ms 53368 KB Output is correct
3 Correct 624 ms 53464 KB Output is correct
4 Correct 638 ms 53504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 629 ms 53460 KB Output is correct
7 Correct 627 ms 53404 KB Output is correct
8 Correct 630 ms 53520 KB Output is correct
9 Correct 695 ms 53324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 637 ms 53368 KB Output is correct
3 Correct 624 ms 53464 KB Output is correct
4 Correct 638 ms 53504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 62 ms 5740 KB Output is correct
7 Correct 67 ms 5872 KB Output is correct
8 Correct 66 ms 5840 KB Output is correct
9 Correct 65 ms 5784 KB Output is correct
10 Correct 74 ms 5740 KB Output is correct
11 Correct 65 ms 5888 KB Output is correct
12 Correct 62 ms 5732 KB Output is correct
13 Correct 69 ms 5736 KB Output is correct
14 Correct 61 ms 5732 KB Output is correct
15 Correct 72 ms 5736 KB Output is correct
16 Correct 68 ms 5864 KB Output is correct
17 Correct 66 ms 5800 KB Output is correct
18 Correct 638 ms 53352 KB Output is correct
19 Correct 622 ms 53412 KB Output is correct
20 Correct 701 ms 53360 KB Output is correct
21 Correct 74 ms 5736 KB Output is correct
22 Correct 61 ms 5736 KB Output is correct
23 Correct 196 ms 18672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 68 ms 5864 KB Output is correct
3 Correct 68 ms 5876 KB Output is correct
4 Correct 729 ms 53364 KB Output is correct
5 Correct 69 ms 5740 KB Output is correct
6 Correct 68 ms 5736 KB Output is correct
7 Correct 67 ms 5736 KB Output is correct
8 Correct 117 ms 5864 KB Output is correct
9 Correct 67 ms 5736 KB Output is correct
10 Correct 68 ms 5736 KB Output is correct
11 Correct 68 ms 5740 KB Output is correct
12 Correct 62 ms 6148 KB Output is correct
13 Correct 69 ms 5736 KB Output is correct
14 Correct 817 ms 52944 KB Output is correct
15 Correct 68 ms 5736 KB Output is correct
16 Correct 621 ms 53448 KB Output is correct
17 Correct 616 ms 53496 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 21 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 10 ms 508 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 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 13 ms 1148 KB Output is correct
17 Correct 70 ms 6016 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 380 KB Output is correct
21 Correct 1 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 0 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 470 ms 41388 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 637 ms 53368 KB Output is correct
31 Correct 624 ms 53464 KB Output is correct
32 Correct 638 ms 53504 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 629 ms 53460 KB Output is correct
35 Correct 627 ms 53404 KB Output is correct
36 Correct 630 ms 53520 KB Output is correct
37 Correct 695 ms 53324 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 62 ms 5740 KB Output is correct
40 Correct 67 ms 5872 KB Output is correct
41 Correct 66 ms 5840 KB Output is correct
42 Correct 65 ms 5784 KB Output is correct
43 Correct 74 ms 5740 KB Output is correct
44 Correct 65 ms 5888 KB Output is correct
45 Correct 62 ms 5732 KB Output is correct
46 Correct 69 ms 5736 KB Output is correct
47 Correct 61 ms 5732 KB Output is correct
48 Correct 72 ms 5736 KB Output is correct
49 Correct 68 ms 5864 KB Output is correct
50 Correct 66 ms 5800 KB Output is correct
51 Correct 638 ms 53352 KB Output is correct
52 Correct 622 ms 53412 KB Output is correct
53 Correct 701 ms 53360 KB Output is correct
54 Correct 74 ms 5736 KB Output is correct
55 Correct 61 ms 5736 KB Output is correct
56 Correct 196 ms 18672 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 68 ms 5864 KB Output is correct
59 Correct 68 ms 5876 KB Output is correct
60 Correct 729 ms 53364 KB Output is correct
61 Correct 69 ms 5740 KB Output is correct
62 Correct 68 ms 5736 KB Output is correct
63 Correct 67 ms 5736 KB Output is correct
64 Correct 117 ms 5864 KB Output is correct
65 Correct 67 ms 5736 KB Output is correct
66 Correct 68 ms 5736 KB Output is correct
67 Correct 68 ms 5740 KB Output is correct
68 Correct 62 ms 6148 KB Output is correct
69 Correct 69 ms 5736 KB Output is correct
70 Correct 817 ms 52944 KB Output is correct
71 Correct 68 ms 5736 KB Output is correct
72 Correct 621 ms 53448 KB Output is correct
73 Correct 616 ms 53496 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 292 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 3 ms 688 KB Output is correct
78 Correct 2 ms 296 KB Output is correct
79 Correct 8 ms 1132 KB Output is correct
80 Correct 758 ms 53376 KB Output is correct
81 Correct 710 ms 53280 KB Output is correct
82 Correct 680 ms 53320 KB Output is correct
83 Correct 692 ms 53308 KB Output is correct
84 Correct 694 ms 53484 KB Output is correct
85 Correct 738 ms 53628 KB Output is correct
86 Correct 196 ms 18520 KB Output is correct
87 Correct 2 ms 376 KB Output is correct