답안 #372476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372476 2021-02-28T09:49:49 Z hivakarami 이상한 기계 (APIO19_strange_device) C++14
100 / 100
551 ms 53700 KB
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
 
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

vector<pair<ll, ll>> v;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	ll a, b;
	cin >> n >> a >> b;
	ll k = a / __gcd(a, b+1);
	if(k > inf/b)
		k = inf;
	else
		k *= b;
	
	//cout << k << endl;
	
	while(n--)
	{
		ll l, r;
		cin >> l >> r;
		
		if(r - l + 1 >= k)
		{
			cout << k << endl;
			return 0;
		}
		
		l = l%k;
		r = r%k;
		
		if(l <= r)
		{
			v.push_back({l, r});
		}
		else
		{
			v.push_back({l, k-1});
			v.push_back({0, r});
		}
		
	}
	
	sort(v.begin(), v.end());
	
	ll ans = 0, mx = -1;
	
	for(int i = 0; i < v.size(); i++)
	{
		ll l = v[i].f, r = v[i].s;
		
		//cout << l << ' ' << r << endl; 
		
		if(l > mx)
			ans += r - l + 1;
		else if(r >= mx)
			ans += r - mx;
		mx = max(mx, r);	
	}
	
	cout << ans << endl;
	
    return 0;
}


 

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 0; i < v.size(); i++)
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 748 KB Output is correct
3 Correct 5 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 48 ms 2584 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 334 ms 16848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 447 ms 16900 KB Output is correct
3 Correct 445 ms 16848 KB Output is correct
4 Correct 432 ms 16848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 447 ms 16900 KB Output is correct
3 Correct 445 ms 16848 KB Output is correct
4 Correct 432 ms 16848 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 442 ms 16856 KB Output is correct
7 Correct 448 ms 16976 KB Output is correct
8 Correct 443 ms 16976 KB Output is correct
9 Correct 491 ms 16848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 447 ms 16900 KB Output is correct
3 Correct 445 ms 16848 KB Output is correct
4 Correct 432 ms 16848 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 44 ms 2524 KB Output is correct
7 Correct 47 ms 2536 KB Output is correct
8 Correct 44 ms 2536 KB Output is correct
9 Correct 44 ms 2536 KB Output is correct
10 Correct 43 ms 2552 KB Output is correct
11 Correct 45 ms 2536 KB Output is correct
12 Correct 44 ms 2536 KB Output is correct
13 Correct 46 ms 2536 KB Output is correct
14 Correct 46 ms 2536 KB Output is correct
15 Correct 48 ms 2536 KB Output is correct
16 Correct 51 ms 2536 KB Output is correct
17 Correct 45 ms 2536 KB Output is correct
18 Correct 448 ms 16848 KB Output is correct
19 Correct 444 ms 16976 KB Output is correct
20 Correct 484 ms 16848 KB Output is correct
21 Correct 46 ms 2536 KB Output is correct
22 Correct 42 ms 2536 KB Output is correct
23 Correct 134 ms 8668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 46 ms 2536 KB Output is correct
3 Correct 47 ms 2536 KB Output is correct
4 Correct 522 ms 16976 KB Output is correct
5 Correct 46 ms 2536 KB Output is correct
6 Correct 46 ms 2536 KB Output is correct
7 Correct 48 ms 2536 KB Output is correct
8 Correct 50 ms 2536 KB Output is correct
9 Correct 45 ms 2536 KB Output is correct
10 Correct 47 ms 2536 KB Output is correct
11 Correct 46 ms 2536 KB Output is correct
12 Correct 41 ms 2536 KB Output is correct
13 Correct 47 ms 2536 KB Output is correct
14 Correct 482 ms 16992 KB Output is correct
15 Correct 47 ms 2536 KB Output is correct
16 Correct 446 ms 16848 KB Output is correct
17 Correct 439 ms 17032 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 748 KB Output is correct
3 Correct 5 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 48 ms 2584 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 0 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 334 ms 16848 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 447 ms 16900 KB Output is correct
31 Correct 445 ms 16848 KB Output is correct
32 Correct 432 ms 16848 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 442 ms 16856 KB Output is correct
35 Correct 448 ms 16976 KB Output is correct
36 Correct 443 ms 16976 KB Output is correct
37 Correct 491 ms 16848 KB Output is correct
38 Correct 0 ms 364 KB Output is correct
39 Correct 44 ms 2524 KB Output is correct
40 Correct 47 ms 2536 KB Output is correct
41 Correct 44 ms 2536 KB Output is correct
42 Correct 44 ms 2536 KB Output is correct
43 Correct 43 ms 2552 KB Output is correct
44 Correct 45 ms 2536 KB Output is correct
45 Correct 44 ms 2536 KB Output is correct
46 Correct 46 ms 2536 KB Output is correct
47 Correct 46 ms 2536 KB Output is correct
48 Correct 48 ms 2536 KB Output is correct
49 Correct 51 ms 2536 KB Output is correct
50 Correct 45 ms 2536 KB Output is correct
51 Correct 448 ms 16848 KB Output is correct
52 Correct 444 ms 16976 KB Output is correct
53 Correct 484 ms 16848 KB Output is correct
54 Correct 46 ms 2536 KB Output is correct
55 Correct 42 ms 2536 KB Output is correct
56 Correct 134 ms 8668 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 46 ms 2536 KB Output is correct
59 Correct 47 ms 2536 KB Output is correct
60 Correct 522 ms 16976 KB Output is correct
61 Correct 46 ms 2536 KB Output is correct
62 Correct 46 ms 2536 KB Output is correct
63 Correct 48 ms 2536 KB Output is correct
64 Correct 50 ms 2536 KB Output is correct
65 Correct 45 ms 2536 KB Output is correct
66 Correct 47 ms 2536 KB Output is correct
67 Correct 46 ms 2536 KB Output is correct
68 Correct 41 ms 2536 KB Output is correct
69 Correct 47 ms 2536 KB Output is correct
70 Correct 482 ms 16992 KB Output is correct
71 Correct 47 ms 2536 KB Output is correct
72 Correct 446 ms 16848 KB Output is correct
73 Correct 439 ms 17032 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 5 ms 1132 KB Output is correct
80 Correct 535 ms 53436 KB Output is correct
81 Correct 551 ms 53508 KB Output is correct
82 Correct 543 ms 53424 KB Output is correct
83 Correct 494 ms 53700 KB Output is correct
84 Correct 540 ms 53308 KB Output is correct
85 Correct 510 ms 53476 KB Output is correct
86 Correct 146 ms 18524 KB Output is correct
87 Correct 1 ms 364 KB Output is correct