답안 #579497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579497 2022-06-19T09:29:12 Z joshjms 이상한 기계 (APIO19_strange_device) C++17
100 / 100
851 ms 163824 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
	cin.tie(0) -> ios_base::sync_with_stdio(0);
 
	ll n, a, b;
	cin >> n >> a >> b;
 
	if(a > 1e18 / b)
	{
		ll sum = 0;
		for(int i = 0; i < n; i++)
		{
			ll l, r;
			cin >> l >> r;
			sum += r - l + 1;
		}
 
		cout << sum;
	}
	else
	{
		ll g = a * b / gcd(a, b + 1);
 
		map<ll, vector<ll>> M;
		for(int i = 0; i < n; i++)
		{
			ll l, r;
			cin >> l >> r;
          
          	if(r - l + 1 >= g) {
              cout << g << "\n";
              return 0;
			}
			l %= g, r %= g;
			if(r < l)
			{
				M[0].push_back(r);
				M[l].push_back(g - 1);
			}
			else
			{
				M[l].push_back(r);
			}
		}
	 
		multiset<ll> S;
		vector<pair<ll,ll>> intervals;
	 
		ll begin = 2e18, last = 0;
		for(auto &[st, v] : M)
		{	
			
			while(!S.empty() && *S.begin() < st)
			{
				S.erase(S.begin());
			}
	 
			if(S.empty() && begin != 2e18)
			{
				intervals.push_back({begin, last});
				begin = 2e18;
				last = 0;
			}
	 
			begin = min(begin, st);
	 
			for(auto i : v)
			{
				S.insert(i);
				last = max(last, i);
			}
	 
		}
	 
		if(!S.empty() && begin != 2e18)
		{
			while(!S.empty())
			{
				last = max(last, *S.begin());
				S.erase(S.begin());
			}
	 
			intervals.push_back({begin, last});
		}
	 
		long long ans = 0;
		for(auto [l, r] : intervals) 
		{
			ans += r - l + 1;
		}
		cout << ans;
	}
 
	
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1876 KB Output is correct
3 Correct 8 ms 1852 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1936 KB Output is correct
17 Correct 71 ms 13716 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 535 ms 55300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 696 ms 126700 KB Output is correct
3 Correct 706 ms 126652 KB Output is correct
4 Correct 708 ms 126636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 696 ms 126700 KB Output is correct
3 Correct 706 ms 126652 KB Output is correct
4 Correct 708 ms 126636 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 767 ms 126648 KB Output is correct
7 Correct 714 ms 126732 KB Output is correct
8 Correct 671 ms 126616 KB Output is correct
9 Correct 710 ms 126664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 696 ms 126700 KB Output is correct
3 Correct 706 ms 126652 KB Output is correct
4 Correct 708 ms 126636 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 69 ms 13652 KB Output is correct
7 Correct 65 ms 13688 KB Output is correct
8 Correct 66 ms 13644 KB Output is correct
9 Correct 82 ms 13652 KB Output is correct
10 Correct 74 ms 13764 KB Output is correct
11 Correct 68 ms 13632 KB Output is correct
12 Correct 66 ms 13604 KB Output is correct
13 Correct 65 ms 13608 KB Output is correct
14 Correct 65 ms 13712 KB Output is correct
15 Correct 98 ms 13676 KB Output is correct
16 Correct 80 ms 13624 KB Output is correct
17 Correct 70 ms 13624 KB Output is correct
18 Correct 696 ms 126608 KB Output is correct
19 Correct 785 ms 126700 KB Output is correct
20 Correct 804 ms 126756 KB Output is correct
21 Correct 65 ms 13704 KB Output is correct
22 Correct 74 ms 13656 KB Output is correct
23 Correct 223 ms 19476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 71 ms 13620 KB Output is correct
3 Correct 70 ms 13704 KB Output is correct
4 Correct 797 ms 126792 KB Output is correct
5 Correct 75 ms 13692 KB Output is correct
6 Correct 68 ms 13680 KB Output is correct
7 Correct 81 ms 13720 KB Output is correct
8 Correct 77 ms 13724 KB Output is correct
9 Correct 70 ms 13640 KB Output is correct
10 Correct 65 ms 13636 KB Output is correct
11 Correct 89 ms 13624 KB Output is correct
12 Correct 73 ms 13684 KB Output is correct
13 Correct 74 ms 13656 KB Output is correct
14 Correct 763 ms 126652 KB Output is correct
15 Correct 64 ms 13768 KB Output is correct
16 Correct 724 ms 126604 KB Output is correct
17 Correct 685 ms 126784 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1876 KB Output is correct
3 Correct 8 ms 1852 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 1936 KB Output is correct
17 Correct 71 ms 13716 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 535 ms 55300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 696 ms 126700 KB Output is correct
31 Correct 706 ms 126652 KB Output is correct
32 Correct 708 ms 126636 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 767 ms 126648 KB Output is correct
35 Correct 714 ms 126732 KB Output is correct
36 Correct 671 ms 126616 KB Output is correct
37 Correct 710 ms 126664 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 69 ms 13652 KB Output is correct
40 Correct 65 ms 13688 KB Output is correct
41 Correct 66 ms 13644 KB Output is correct
42 Correct 82 ms 13652 KB Output is correct
43 Correct 74 ms 13764 KB Output is correct
44 Correct 68 ms 13632 KB Output is correct
45 Correct 66 ms 13604 KB Output is correct
46 Correct 65 ms 13608 KB Output is correct
47 Correct 65 ms 13712 KB Output is correct
48 Correct 98 ms 13676 KB Output is correct
49 Correct 80 ms 13624 KB Output is correct
50 Correct 70 ms 13624 KB Output is correct
51 Correct 696 ms 126608 KB Output is correct
52 Correct 785 ms 126700 KB Output is correct
53 Correct 804 ms 126756 KB Output is correct
54 Correct 65 ms 13704 KB Output is correct
55 Correct 74 ms 13656 KB Output is correct
56 Correct 223 ms 19476 KB Output is correct
57 Correct 1 ms 320 KB Output is correct
58 Correct 71 ms 13620 KB Output is correct
59 Correct 70 ms 13704 KB Output is correct
60 Correct 797 ms 126792 KB Output is correct
61 Correct 75 ms 13692 KB Output is correct
62 Correct 68 ms 13680 KB Output is correct
63 Correct 81 ms 13720 KB Output is correct
64 Correct 77 ms 13724 KB Output is correct
65 Correct 70 ms 13640 KB Output is correct
66 Correct 65 ms 13636 KB Output is correct
67 Correct 89 ms 13624 KB Output is correct
68 Correct 73 ms 13684 KB Output is correct
69 Correct 74 ms 13656 KB Output is correct
70 Correct 763 ms 126652 KB Output is correct
71 Correct 64 ms 13768 KB Output is correct
72 Correct 724 ms 126604 KB Output is correct
73 Correct 685 ms 126784 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 256 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 10 ms 2128 KB Output is correct
80 Correct 835 ms 163640 KB Output is correct
81 Correct 785 ms 163824 KB Output is correct
82 Correct 773 ms 163696 KB Output is correct
83 Correct 771 ms 163332 KB Output is correct
84 Correct 851 ms 163284 KB Output is correct
85 Correct 818 ms 163392 KB Output is correct
86 Correct 206 ms 31420 KB Output is correct
87 Correct 1 ms 212 KB Output is correct