Submission #154724

# Submission time Handle Problem Language Result Execution time Memory
154724 2019-09-24T09:04:09 Z Pro_ktmr Strange Device (APIO19_strange_device) C++14
100 / 100
2745 ms 17492 KB
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair

LL gcd(LL a, LL b){
	if(a%b == 0) return b;
	return gcd(b, a%b);
}

int N;
LL A, B, S;
vector<pair<LL,LL>> all; //closed range

int main(){
	cin >> N >> A >> B;
	S = A*B/gcd(A, B+1);
	//cout << S << endl;
	for(int i=0; i<N; i++){
		LL l, r;
		cin >> l >> r;
		if(l/S == r/S){
			all.push_back(MP(l%S, r%S));
			//cout << l%S << " " << r%S << endl;
		}
		else if(l/S+1 == r/S){
			all.push_back(MP(l%S, S-1));
			all.push_back(MP(0, r%S));
			//cout << l%S << " " << S-1 << endl;
			//cout << 0 << " " << r%S << endl;
		}
		else{
			all.push_back(MP(0, S-1));
			//cout << 0 << " " << S-1 << endl;
		}
	}
	sort(all.begin(), all.end());
	for(int i=0; i<all.size()-1; i++){
		if(all[i+1].first <= all[i].second){
			all[i+1].first = all[i].first;
			all[i+1].second = max(all[i].second, all[i+1].second);
			all[i] = MP(-1,-2);
		}
	}
	LL ans = 0;
	for(int i=0; i<all.size(); i++){
		//cout << all[i].first << " " << all[i].second << " " << all[i].second - all[i].first + 1 << endl;
		ans += all[i].second - all[i].first + 1;
	}
	cout << ans << endl;
	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<all.size()-1; i++){
               ~^~~~~~~~~~~~~
strange_device.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<all.size(); i++){
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 29 ms 1144 KB Output is correct
3 Correct 29 ms 1016 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 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 28 ms 1016 KB Output is correct
17 Correct 271 ms 3308 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 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 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 1880 ms 17324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2645 ms 17492 KB Output is correct
3 Correct 2647 ms 17276 KB Output is correct
4 Correct 2637 ms 17388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2645 ms 17492 KB Output is correct
3 Correct 2647 ms 17276 KB Output is correct
4 Correct 2637 ms 17388 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2639 ms 17456 KB Output is correct
7 Correct 2658 ms 17400 KB Output is correct
8 Correct 2686 ms 17272 KB Output is correct
9 Correct 2698 ms 17464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2645 ms 17492 KB Output is correct
3 Correct 2647 ms 17276 KB Output is correct
4 Correct 2637 ms 17388 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 263 ms 3180 KB Output is correct
7 Correct 267 ms 3304 KB Output is correct
8 Correct 264 ms 3180 KB Output is correct
9 Correct 265 ms 3176 KB Output is correct
10 Correct 268 ms 3212 KB Output is correct
11 Correct 268 ms 3180 KB Output is correct
12 Correct 264 ms 3180 KB Output is correct
13 Correct 271 ms 3208 KB Output is correct
14 Correct 266 ms 3176 KB Output is correct
15 Correct 275 ms 3184 KB Output is correct
16 Correct 275 ms 3380 KB Output is correct
17 Correct 269 ms 3176 KB Output is correct
18 Correct 2640 ms 17276 KB Output is correct
19 Correct 2637 ms 17240 KB Output is correct
20 Correct 2708 ms 17360 KB Output is correct
21 Correct 271 ms 2824 KB Output is correct
22 Correct 263 ms 2796 KB Output is correct
23 Correct 891 ms 9000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 289 ms 2820 KB Output is correct
3 Correct 271 ms 2796 KB Output is correct
4 Correct 2733 ms 17056 KB Output is correct
5 Correct 269 ms 2768 KB Output is correct
6 Correct 270 ms 2792 KB Output is correct
7 Correct 269 ms 2896 KB Output is correct
8 Correct 271 ms 2764 KB Output is correct
9 Correct 269 ms 2792 KB Output is correct
10 Correct 274 ms 2760 KB Output is correct
11 Correct 271 ms 2796 KB Output is correct
12 Correct 266 ms 2792 KB Output is correct
13 Correct 270 ms 2740 KB Output is correct
14 Correct 2693 ms 16896 KB Output is correct
15 Correct 268 ms 2796 KB Output is correct
16 Correct 2745 ms 17164 KB Output is correct
17 Correct 2631 ms 17180 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 29 ms 1144 KB Output is correct
3 Correct 29 ms 1016 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 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 28 ms 1016 KB Output is correct
17 Correct 271 ms 3308 KB Output is correct
18 Correct 2 ms 256 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 256 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 256 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 1880 ms 17324 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2645 ms 17492 KB Output is correct
31 Correct 2647 ms 17276 KB Output is correct
32 Correct 2637 ms 17388 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2639 ms 17456 KB Output is correct
35 Correct 2658 ms 17400 KB Output is correct
36 Correct 2686 ms 17272 KB Output is correct
37 Correct 2698 ms 17464 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 263 ms 3180 KB Output is correct
40 Correct 267 ms 3304 KB Output is correct
41 Correct 264 ms 3180 KB Output is correct
42 Correct 265 ms 3176 KB Output is correct
43 Correct 268 ms 3212 KB Output is correct
44 Correct 268 ms 3180 KB Output is correct
45 Correct 264 ms 3180 KB Output is correct
46 Correct 271 ms 3208 KB Output is correct
47 Correct 266 ms 3176 KB Output is correct
48 Correct 275 ms 3184 KB Output is correct
49 Correct 275 ms 3380 KB Output is correct
50 Correct 269 ms 3176 KB Output is correct
51 Correct 2640 ms 17276 KB Output is correct
52 Correct 2637 ms 17240 KB Output is correct
53 Correct 2708 ms 17360 KB Output is correct
54 Correct 271 ms 2824 KB Output is correct
55 Correct 263 ms 2796 KB Output is correct
56 Correct 891 ms 9000 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 289 ms 2820 KB Output is correct
59 Correct 271 ms 2796 KB Output is correct
60 Correct 2733 ms 17056 KB Output is correct
61 Correct 269 ms 2768 KB Output is correct
62 Correct 270 ms 2792 KB Output is correct
63 Correct 269 ms 2896 KB Output is correct
64 Correct 271 ms 2764 KB Output is correct
65 Correct 269 ms 2792 KB Output is correct
66 Correct 274 ms 2760 KB Output is correct
67 Correct 271 ms 2796 KB Output is correct
68 Correct 266 ms 2792 KB Output is correct
69 Correct 270 ms 2740 KB Output is correct
70 Correct 2693 ms 16896 KB Output is correct
71 Correct 268 ms 2796 KB Output is correct
72 Correct 2745 ms 17164 KB Output is correct
73 Correct 2631 ms 17180 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 256 KB Output is correct
76 Correct 3 ms 376 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 2 ms 380 KB Output is correct
79 Correct 30 ms 1144 KB Output is correct
80 Correct 2721 ms 16944 KB Output is correct
81 Correct 2739 ms 16944 KB Output is correct
82 Correct 2719 ms 16948 KB Output is correct
83 Correct 2696 ms 16956 KB Output is correct
84 Correct 2708 ms 16976 KB Output is correct
85 Correct 2696 ms 16948 KB Output is correct
86 Correct 885 ms 9024 KB Output is correct
87 Correct 2 ms 256 KB Output is correct