Submission #977112

# Submission time Handle Problem Language Result Execution time Memory
977112 2024-05-07T11:50:06 Z Batorgil952 Strange Device (APIO19_strange_device) C++14
100 / 100
404 ms 18804 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
using namespace std;
 
ll GCD(ll x, ll y){
	while(x*y!=0){
		if(x>y) x%=y;
		else y%=x;
	}
	return x+y;
}
 
int main(){
	ll n, i, A, B, l, r, k, m, ma, ans, vn;
	vector< pair< ll, ll > > v;
	
	scanf("%lld",&n);
	scanf("%lld",&A);
	scanf("%lld",&B);
	
	m=GCD(B+1, A);
	A/=m;
	ma=1000000000000000002;
	if(ma/A<B){
		k=ma;
	}
	else{
		k=A*B;
	}
//	cout<<k<<endl;
	
	ans=0;
	for(i=1; i<=n; i++){
		scanf("%lld",&l);
		scanf("%lld",&r);
		if(r-l+1>=k){
			ans=k;
		}
		if(l%k<=r%k) v.pb(mp(l%k, r%k));
		else{
			v.pb(mp(l%k, k-1));
			v.pb(mp(0, r%k));
		}
	}
	
	
	if(ans==k){
		printf("%lld\n", k);
		return 0;
	}
	sort(v.begin(), v.end());
	
	l=v[0].ff;
	r=v[0].ss;
	vn=v.size();
	for(i=1; i<vn; i++){
		if(v[i].ff<=r){
			r=max(r, v[i].ss);
		}
		else{
			ans+=(r-l+1);
			l=v[i].ff;
			r=v[i].ss;
		}
	}
	ans+=(r-l+1);
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%lld",&A);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%lld",&B);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld",&l);
      |   ~~~~~^~~~~~~~~~~
strange_device.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%lld",&r);
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 4 ms 728 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 33 ms 2512 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 222 ms 18160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 300 ms 17328 KB Output is correct
3 Correct 309 ms 18504 KB Output is correct
4 Correct 287 ms 17596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 300 ms 17328 KB Output is correct
3 Correct 309 ms 18504 KB Output is correct
4 Correct 287 ms 17596 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 300 ms 18108 KB Output is correct
7 Correct 298 ms 17836 KB Output is correct
8 Correct 305 ms 18488 KB Output is correct
9 Correct 332 ms 17348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 300 ms 17328 KB Output is correct
3 Correct 309 ms 18504 KB Output is correct
4 Correct 287 ms 17596 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 30 ms 2420 KB Output is correct
7 Correct 32 ms 2512 KB Output is correct
8 Correct 30 ms 2584 KB Output is correct
9 Correct 30 ms 2508 KB Output is correct
10 Correct 31 ms 2512 KB Output is correct
11 Correct 30 ms 2512 KB Output is correct
12 Correct 29 ms 2512 KB Output is correct
13 Correct 33 ms 2436 KB Output is correct
14 Correct 29 ms 2508 KB Output is correct
15 Correct 35 ms 2512 KB Output is correct
16 Correct 33 ms 2536 KB Output is correct
17 Correct 31 ms 2512 KB Output is correct
18 Correct 321 ms 16880 KB Output is correct
19 Correct 300 ms 17676 KB Output is correct
20 Correct 326 ms 17796 KB Output is correct
21 Correct 32 ms 2508 KB Output is correct
22 Correct 28 ms 2416 KB Output is correct
23 Correct 91 ms 10424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 34 ms 2512 KB Output is correct
3 Correct 37 ms 2512 KB Output is correct
4 Correct 356 ms 17584 KB Output is correct
5 Correct 44 ms 2504 KB Output is correct
6 Correct 34 ms 2508 KB Output is correct
7 Correct 32 ms 2508 KB Output is correct
8 Correct 34 ms 2512 KB Output is correct
9 Correct 42 ms 2508 KB Output is correct
10 Correct 33 ms 2512 KB Output is correct
11 Correct 34 ms 2512 KB Output is correct
12 Correct 28 ms 2512 KB Output is correct
13 Correct 32 ms 2540 KB Output is correct
14 Correct 329 ms 18052 KB Output is correct
15 Correct 33 ms 2508 KB Output is correct
16 Correct 310 ms 17324 KB Output is correct
17 Correct 299 ms 17364 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 4 ms 728 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 33 ms 2512 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 222 ms 18160 KB Output is correct
29 Correct 0 ms 596 KB Output is correct
30 Correct 300 ms 17328 KB Output is correct
31 Correct 309 ms 18504 KB Output is correct
32 Correct 287 ms 17596 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 300 ms 18108 KB Output is correct
35 Correct 298 ms 17836 KB Output is correct
36 Correct 305 ms 18488 KB Output is correct
37 Correct 332 ms 17348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 30 ms 2420 KB Output is correct
40 Correct 32 ms 2512 KB Output is correct
41 Correct 30 ms 2584 KB Output is correct
42 Correct 30 ms 2508 KB Output is correct
43 Correct 31 ms 2512 KB Output is correct
44 Correct 30 ms 2512 KB Output is correct
45 Correct 29 ms 2512 KB Output is correct
46 Correct 33 ms 2436 KB Output is correct
47 Correct 29 ms 2508 KB Output is correct
48 Correct 35 ms 2512 KB Output is correct
49 Correct 33 ms 2536 KB Output is correct
50 Correct 31 ms 2512 KB Output is correct
51 Correct 321 ms 16880 KB Output is correct
52 Correct 300 ms 17676 KB Output is correct
53 Correct 326 ms 17796 KB Output is correct
54 Correct 32 ms 2508 KB Output is correct
55 Correct 28 ms 2416 KB Output is correct
56 Correct 91 ms 10424 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 34 ms 2512 KB Output is correct
59 Correct 37 ms 2512 KB Output is correct
60 Correct 356 ms 17584 KB Output is correct
61 Correct 44 ms 2504 KB Output is correct
62 Correct 34 ms 2508 KB Output is correct
63 Correct 32 ms 2508 KB Output is correct
64 Correct 34 ms 2512 KB Output is correct
65 Correct 42 ms 2508 KB Output is correct
66 Correct 33 ms 2512 KB Output is correct
67 Correct 34 ms 2512 KB Output is correct
68 Correct 28 ms 2512 KB Output is correct
69 Correct 32 ms 2540 KB Output is correct
70 Correct 329 ms 18052 KB Output is correct
71 Correct 33 ms 2508 KB Output is correct
72 Correct 310 ms 17324 KB Output is correct
73 Correct 299 ms 17364 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 812 KB Output is correct
80 Correct 404 ms 17240 KB Output is correct
81 Correct 388 ms 17620 KB Output is correct
82 Correct 330 ms 18348 KB Output is correct
83 Correct 329 ms 18348 KB Output is correct
84 Correct 326 ms 18804 KB Output is correct
85 Correct 329 ms 17836 KB Output is correct
86 Correct 90 ms 10780 KB Output is correct
87 Correct 0 ms 344 KB Output is correct