Submission #408957

# Submission time Handle Problem Language Result Execution time Memory
408957 2021-05-19T22:28:57 Z MohamedAhmed04 Strange Device (APIO19_strange_device) C++14
100 / 100
551 ms 25312 KB
#include <bits/stdc++.h>

using namespace std ;

const long long inf = 4e18 ;
const int MAX = 1e5 + 10 ;

bool Overflow_Mul(long double x , long double y)
{
	return (x * y > inf) ;
}

int arr[MAX] ;
int n ;
long long a , b ;

vector< pair<long long , long long> >vp ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>a>>b ;
	long long x = a / __gcd(a , b+1ll) ;
	if(Overflow_Mul(x , b))
		x = inf ;
	else
		x *= b ;
	long long st = -1 ;
	for(int i = 0 ; i < n ; ++i)
	{
		long long l , r ;
		cin>>l>>r ;
		if(r-l+1ll >= x)
			return cout<<x<<"\n" , 0 ;
		if((r % x) < (l % x))
			st = max(st , (r % x)) , vp.emplace_back((l % x) , x-1ll) ;
		else
			vp.emplace_back((l % x) , (r % x)) ;
	}
	sort(vp.begin() , vp.end()) ;
	long long ans = st+1ll , Max = st ;
	for(auto &p : vp)
	{
		Max = max(Max , p.first - 1ll) ;
		ans += max(0ll , p.second - Max) ;
		Max = max(Max , p.second) ;
	}
	return cout<<ans<<"\n" , 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 976 KB Output is correct
3 Correct 6 ms 1072 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 976 KB Output is correct
17 Correct 56 ms 5628 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 359 ms 22696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 494 ms 23076 KB Output is correct
3 Correct 497 ms 23184 KB Output is correct
4 Correct 471 ms 23148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 494 ms 23076 KB Output is correct
3 Correct 497 ms 23184 KB Output is correct
4 Correct 471 ms 23148 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 477 ms 23128 KB Output is correct
7 Correct 482 ms 25312 KB Output is correct
8 Correct 469 ms 25264 KB Output is correct
9 Correct 546 ms 25260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 494 ms 23076 KB Output is correct
3 Correct 497 ms 23184 KB Output is correct
4 Correct 471 ms 23148 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 47 ms 5680 KB Output is correct
7 Correct 51 ms 5708 KB Output is correct
8 Correct 47 ms 5656 KB Output is correct
9 Correct 49 ms 5716 KB Output is correct
10 Correct 47 ms 5708 KB Output is correct
11 Correct 50 ms 5692 KB Output is correct
12 Correct 47 ms 5640 KB Output is correct
13 Correct 51 ms 5688 KB Output is correct
14 Correct 48 ms 5688 KB Output is correct
15 Correct 52 ms 5680 KB Output is correct
16 Correct 55 ms 5760 KB Output is correct
17 Correct 53 ms 5720 KB Output is correct
18 Correct 494 ms 23168 KB Output is correct
19 Correct 468 ms 23192 KB Output is correct
20 Correct 528 ms 23244 KB Output is correct
21 Correct 53 ms 5616 KB Output is correct
22 Correct 46 ms 5616 KB Output is correct
23 Correct 148 ms 18404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 55 ms 5648 KB Output is correct
3 Correct 52 ms 5692 KB Output is correct
4 Correct 548 ms 23188 KB Output is correct
5 Correct 52 ms 5856 KB Output is correct
6 Correct 51 ms 5824 KB Output is correct
7 Correct 52 ms 5636 KB Output is correct
8 Correct 53 ms 5704 KB Output is correct
9 Correct 51 ms 5640 KB Output is correct
10 Correct 53 ms 5716 KB Output is correct
11 Correct 52 ms 5688 KB Output is correct
12 Correct 46 ms 5632 KB Output is correct
13 Correct 55 ms 5688 KB Output is correct
14 Correct 531 ms 23248 KB Output is correct
15 Correct 51 ms 5692 KB Output is correct
16 Correct 474 ms 23208 KB Output is correct
17 Correct 477 ms 23348 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 976 KB Output is correct
3 Correct 6 ms 1072 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 976 KB Output is correct
17 Correct 56 ms 5628 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 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 359 ms 22696 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 494 ms 23076 KB Output is correct
31 Correct 497 ms 23184 KB Output is correct
32 Correct 471 ms 23148 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 477 ms 23128 KB Output is correct
35 Correct 482 ms 25312 KB Output is correct
36 Correct 469 ms 25264 KB Output is correct
37 Correct 546 ms 25260 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 47 ms 5680 KB Output is correct
40 Correct 51 ms 5708 KB Output is correct
41 Correct 47 ms 5656 KB Output is correct
42 Correct 49 ms 5716 KB Output is correct
43 Correct 47 ms 5708 KB Output is correct
44 Correct 50 ms 5692 KB Output is correct
45 Correct 47 ms 5640 KB Output is correct
46 Correct 51 ms 5688 KB Output is correct
47 Correct 48 ms 5688 KB Output is correct
48 Correct 52 ms 5680 KB Output is correct
49 Correct 55 ms 5760 KB Output is correct
50 Correct 53 ms 5720 KB Output is correct
51 Correct 494 ms 23168 KB Output is correct
52 Correct 468 ms 23192 KB Output is correct
53 Correct 528 ms 23244 KB Output is correct
54 Correct 53 ms 5616 KB Output is correct
55 Correct 46 ms 5616 KB Output is correct
56 Correct 148 ms 18404 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 55 ms 5648 KB Output is correct
59 Correct 52 ms 5692 KB Output is correct
60 Correct 548 ms 23188 KB Output is correct
61 Correct 52 ms 5856 KB Output is correct
62 Correct 51 ms 5824 KB Output is correct
63 Correct 52 ms 5636 KB Output is correct
64 Correct 53 ms 5704 KB Output is correct
65 Correct 51 ms 5640 KB Output is correct
66 Correct 53 ms 5716 KB Output is correct
67 Correct 52 ms 5688 KB Output is correct
68 Correct 46 ms 5632 KB Output is correct
69 Correct 55 ms 5688 KB Output is correct
70 Correct 531 ms 23248 KB Output is correct
71 Correct 51 ms 5692 KB Output is correct
72 Correct 474 ms 23208 KB Output is correct
73 Correct 477 ms 23348 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 976 KB Output is correct
80 Correct 550 ms 22184 KB Output is correct
81 Correct 551 ms 22372 KB Output is correct
82 Correct 521 ms 22444 KB Output is correct
83 Correct 520 ms 22416 KB Output is correct
84 Correct 525 ms 22392 KB Output is correct
85 Correct 523 ms 22436 KB Output is correct
86 Correct 148 ms 18440 KB Output is correct
87 Correct 1 ms 332 KB Output is correct