답안 #476636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476636 2021-09-27T20:32:19 Z thiago_bastos 이상한 기계 (APIO19_strange_device) C++17
100 / 100
778 ms 46640 KB
#include "bits/stdc++.h"
 
using namespace std;
 
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

void solve() {
/*
	t1 < t2
	
	t2 = t1 + Bk
	
	t1 + t1 / B = t1 + Bk + (t1 + Bk) / B mod A
	
	t1 / B = Bk + (t1 + Bk) / B mod A
	
	t1 / B = Bk + t1 / B + k mod A
	
	0 = Bk + k mod A
	
	0 = k(B + 1) mod A
	
	C = AB/gcd(A, B + 1)
	
	t2 = t1 + Ck'
	
	t2 = t1 mod C
*/

	int n;
	i64 A, B;
	
	cin >> n >> A >> B;
	
	__int128 C = (__int128)A * B / gcd(A, B + 1);
	
	vector<pair<i64, int>> sweep;
	
	for(int i = 0; i < n; ++i) {
		i64 l, r;
		cin >> l >> r;
		
		if(r - l + 1 >= C) {
			sweep.push_back({0, 1});
			sweep.push_back({C, -1});
			continue;
		}
		
		i64 L = l % C, R = r % C;

		if(L <= R) {
			sweep.push_back({L, 1});
			sweep.push_back({R + 1, -1});
		} else {
			sweep.push_back({L, 1});
			sweep.push_back({C, -1});
			sweep.push_back({0, 1});
			sweep.push_back({R + 1, -1});
		}
	}
	
	sort(sweep.begin(), sweep.end());
	
	i64 ans = 0;
	int abertos = 0;
	
	for(int i = 0; i < (int)size(sweep); ++i) {
		auto [x, type] = sweep[i];
		if(abertos) ans += x - sweep[i - 1].first;
		abertos += type;
	}
	
	cout << ans << '\n';
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
 	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 1232 KB Output is correct
3 Correct 6 ms 1232 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 6 ms 1232 KB Output is correct
17 Correct 61 ms 7212 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 391 ms 33816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 562 ms 44136 KB Output is correct
3 Correct 550 ms 33764 KB Output is correct
4 Correct 574 ms 34136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 562 ms 44136 KB Output is correct
3 Correct 550 ms 33764 KB Output is correct
4 Correct 574 ms 34136 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 604 ms 34308 KB Output is correct
7 Correct 539 ms 34180 KB Output is correct
8 Correct 570 ms 34068 KB Output is correct
9 Correct 651 ms 34028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 562 ms 44136 KB Output is correct
3 Correct 550 ms 33764 KB Output is correct
4 Correct 574 ms 34136 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 53 ms 7232 KB Output is correct
7 Correct 58 ms 7248 KB Output is correct
8 Correct 55 ms 7188 KB Output is correct
9 Correct 53 ms 7236 KB Output is correct
10 Correct 55 ms 7204 KB Output is correct
11 Correct 59 ms 7260 KB Output is correct
12 Correct 52 ms 7276 KB Output is correct
13 Correct 58 ms 7284 KB Output is correct
14 Correct 52 ms 7236 KB Output is correct
15 Correct 63 ms 7280 KB Output is correct
16 Correct 60 ms 7168 KB Output is correct
17 Correct 55 ms 7224 KB Output is correct
18 Correct 560 ms 34148 KB Output is correct
19 Correct 539 ms 34016 KB Output is correct
20 Correct 648 ms 34388 KB Output is correct
21 Correct 61 ms 7224 KB Output is correct
22 Correct 47 ms 7220 KB Output is correct
23 Correct 188 ms 26684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 64 ms 7240 KB Output is correct
3 Correct 64 ms 7200 KB Output is correct
4 Correct 716 ms 34440 KB Output is correct
5 Correct 57 ms 7228 KB Output is correct
6 Correct 58 ms 7180 KB Output is correct
7 Correct 64 ms 7244 KB Output is correct
8 Correct 60 ms 7192 KB Output is correct
9 Correct 63 ms 7228 KB Output is correct
10 Correct 62 ms 7284 KB Output is correct
11 Correct 60 ms 7208 KB Output is correct
12 Correct 53 ms 7248 KB Output is correct
13 Correct 66 ms 7220 KB Output is correct
14 Correct 704 ms 34500 KB Output is correct
15 Correct 66 ms 7244 KB Output is correct
16 Correct 554 ms 34392 KB Output is correct
17 Correct 554 ms 34576 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 1232 KB Output is correct
3 Correct 6 ms 1232 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 6 ms 1232 KB Output is correct
17 Correct 61 ms 7212 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 391 ms 33816 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 562 ms 44136 KB Output is correct
31 Correct 550 ms 33764 KB Output is correct
32 Correct 574 ms 34136 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 604 ms 34308 KB Output is correct
35 Correct 539 ms 34180 KB Output is correct
36 Correct 570 ms 34068 KB Output is correct
37 Correct 651 ms 34028 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 53 ms 7232 KB Output is correct
40 Correct 58 ms 7248 KB Output is correct
41 Correct 55 ms 7188 KB Output is correct
42 Correct 53 ms 7236 KB Output is correct
43 Correct 55 ms 7204 KB Output is correct
44 Correct 59 ms 7260 KB Output is correct
45 Correct 52 ms 7276 KB Output is correct
46 Correct 58 ms 7284 KB Output is correct
47 Correct 52 ms 7236 KB Output is correct
48 Correct 63 ms 7280 KB Output is correct
49 Correct 60 ms 7168 KB Output is correct
50 Correct 55 ms 7224 KB Output is correct
51 Correct 560 ms 34148 KB Output is correct
52 Correct 539 ms 34016 KB Output is correct
53 Correct 648 ms 34388 KB Output is correct
54 Correct 61 ms 7224 KB Output is correct
55 Correct 47 ms 7220 KB Output is correct
56 Correct 188 ms 26684 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 64 ms 7240 KB Output is correct
59 Correct 64 ms 7200 KB Output is correct
60 Correct 716 ms 34440 KB Output is correct
61 Correct 57 ms 7228 KB Output is correct
62 Correct 58 ms 7180 KB Output is correct
63 Correct 64 ms 7244 KB Output is correct
64 Correct 60 ms 7192 KB Output is correct
65 Correct 63 ms 7228 KB Output is correct
66 Correct 62 ms 7284 KB Output is correct
67 Correct 60 ms 7208 KB Output is correct
68 Correct 53 ms 7248 KB Output is correct
69 Correct 66 ms 7220 KB Output is correct
70 Correct 704 ms 34500 KB Output is correct
71 Correct 66 ms 7244 KB Output is correct
72 Correct 554 ms 34392 KB Output is correct
73 Correct 554 ms 34576 KB Output is correct
74 Correct 0 ms 204 KB Output is correct
75 Correct 0 ms 204 KB Output is correct
76 Correct 0 ms 312 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 5 ms 1224 KB Output is correct
80 Correct 778 ms 45056 KB Output is correct
81 Correct 743 ms 44992 KB Output is correct
82 Correct 673 ms 45080 KB Output is correct
83 Correct 653 ms 45056 KB Output is correct
84 Correct 676 ms 46432 KB Output is correct
85 Correct 631 ms 46640 KB Output is correct
86 Correct 146 ms 26660 KB Output is correct
87 Correct 0 ms 204 KB Output is correct