Submission #124493

# Submission time Handle Problem Language Result Execution time Memory
124493 2019-07-03T12:12:55 Z TadijaSebez Strange Device (APIO19_strange_device) C++11
100 / 100
986 ms 51284 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll inf=9e18;
const int N=1000050;
ll l[N],r[N];
int main()
{
	int n;
	ll A,B;
	scanf("%i %lld %lld",&n,&A,&B);
	for(int i=1;i<=n;i++) scanf("%lld %lld",&l[i],&r[i]);
	ll x=A/__gcd(A,B+1);
	if(inf/x>B)
	{
		ll P=x*B;
		//printf("P:%lld\n",P);
		bool all=0;
		vector<pair<ll,int>> evs;
		for(int i=1;i<=n;i++)
		{
			if(r[i]-l[i]+1>=P) all=1;
			r[i]%=P;
			l[i]%=P;
			if(r[i]<l[i]) evs.pb({0,1}),evs.pb({P,-1});
			evs.pb({l[i],1});
			evs.pb({r[i]+1,-1});
		}
		if(all) printf("%lld\n",P);
		else
		{
			int cur=0;
			sort(evs.begin(),evs.end());
			ll ltm=-1,ans=0;
			for(pair<ll,int> e:evs)
			{
				ll tme=e.first-ltm;
				//printf("(%lld - %lld) cur:%i\n",ltm,e.first,cur);
				ltm=e.first;
				if(cur) ans+=tme;
				cur+=e.second;
			}
			printf("%lld\n",ans);
		}
	}
	else
	{
		ll sum=0;
		for(int i=1;i<=n;i++) sum+=r[i]-l[i]+1;
		printf("%lld\n",sum);
	}
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %lld %lld",&n,&A,&B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:13:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%lld %lld",&l[i],&r[i]);
                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1140 KB Output is correct
3 Correct 10 ms 1268 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 248 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 81 ms 6884 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 444 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 553 ms 51284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 689 ms 48892 KB Output is correct
3 Correct 734 ms 49068 KB Output is correct
4 Correct 704 ms 49112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 689 ms 48892 KB Output is correct
3 Correct 734 ms 49068 KB Output is correct
4 Correct 704 ms 49112 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 744 ms 49124 KB Output is correct
7 Correct 693 ms 49492 KB Output is correct
8 Correct 714 ms 49584 KB Output is correct
9 Correct 823 ms 49624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 689 ms 48892 KB Output is correct
3 Correct 734 ms 49068 KB Output is correct
4 Correct 704 ms 49112 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 67 ms 6688 KB Output is correct
7 Correct 72 ms 9640 KB Output is correct
8 Correct 69 ms 9572 KB Output is correct
9 Correct 74 ms 9548 KB Output is correct
10 Correct 67 ms 9572 KB Output is correct
11 Correct 73 ms 9580 KB Output is correct
12 Correct 68 ms 9548 KB Output is correct
13 Correct 81 ms 9544 KB Output is correct
14 Correct 69 ms 9636 KB Output is correct
15 Correct 79 ms 9572 KB Output is correct
16 Correct 78 ms 9700 KB Output is correct
17 Correct 73 ms 9572 KB Output is correct
18 Correct 725 ms 49588 KB Output is correct
19 Correct 671 ms 49508 KB Output is correct
20 Correct 855 ms 49528 KB Output is correct
21 Correct 81 ms 9524 KB Output is correct
22 Correct 63 ms 9544 KB Output is correct
23 Correct 235 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 77 ms 6860 KB Output is correct
3 Correct 78 ms 9748 KB Output is correct
4 Correct 908 ms 49560 KB Output is correct
5 Correct 79 ms 9700 KB Output is correct
6 Correct 80 ms 9768 KB Output is correct
7 Correct 79 ms 9704 KB Output is correct
8 Correct 80 ms 9704 KB Output is correct
9 Correct 76 ms 9700 KB Output is correct
10 Correct 81 ms 9760 KB Output is correct
11 Correct 79 ms 9772 KB Output is correct
12 Correct 71 ms 9572 KB Output is correct
13 Correct 81 ms 9700 KB Output is correct
14 Correct 805 ms 49600 KB Output is correct
15 Correct 81 ms 9700 KB Output is correct
16 Correct 665 ms 49596 KB Output is correct
17 Correct 702 ms 49528 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1140 KB Output is correct
3 Correct 10 ms 1268 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 248 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 81 ms 6884 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 252 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 252 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 444 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 553 ms 51284 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 689 ms 48892 KB Output is correct
31 Correct 734 ms 49068 KB Output is correct
32 Correct 704 ms 49112 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 744 ms 49124 KB Output is correct
35 Correct 693 ms 49492 KB Output is correct
36 Correct 714 ms 49584 KB Output is correct
37 Correct 823 ms 49624 KB Output is correct
38 Correct 2 ms 252 KB Output is correct
39 Correct 67 ms 6688 KB Output is correct
40 Correct 72 ms 9640 KB Output is correct
41 Correct 69 ms 9572 KB Output is correct
42 Correct 74 ms 9548 KB Output is correct
43 Correct 67 ms 9572 KB Output is correct
44 Correct 73 ms 9580 KB Output is correct
45 Correct 68 ms 9548 KB Output is correct
46 Correct 81 ms 9544 KB Output is correct
47 Correct 69 ms 9636 KB Output is correct
48 Correct 79 ms 9572 KB Output is correct
49 Correct 78 ms 9700 KB Output is correct
50 Correct 73 ms 9572 KB Output is correct
51 Correct 725 ms 49588 KB Output is correct
52 Correct 671 ms 49508 KB Output is correct
53 Correct 855 ms 49528 KB Output is correct
54 Correct 81 ms 9524 KB Output is correct
55 Correct 63 ms 9544 KB Output is correct
56 Correct 235 ms 23888 KB Output is correct
57 Correct 3 ms 256 KB Output is correct
58 Correct 77 ms 6860 KB Output is correct
59 Correct 78 ms 9748 KB Output is correct
60 Correct 908 ms 49560 KB Output is correct
61 Correct 79 ms 9700 KB Output is correct
62 Correct 80 ms 9768 KB Output is correct
63 Correct 79 ms 9704 KB Output is correct
64 Correct 80 ms 9704 KB Output is correct
65 Correct 76 ms 9700 KB Output is correct
66 Correct 81 ms 9760 KB Output is correct
67 Correct 79 ms 9772 KB Output is correct
68 Correct 71 ms 9572 KB Output is correct
69 Correct 81 ms 9700 KB Output is correct
70 Correct 805 ms 49600 KB Output is correct
71 Correct 81 ms 9700 KB Output is correct
72 Correct 665 ms 49596 KB Output is correct
73 Correct 702 ms 49528 KB Output is correct
74 Correct 2 ms 256 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 0 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 1524 KB Output is correct
80 Correct 986 ms 49540 KB Output is correct
81 Correct 918 ms 49540 KB Output is correct
82 Correct 809 ms 49600 KB Output is correct
83 Correct 810 ms 49576 KB Output is correct
84 Correct 866 ms 49792 KB Output is correct
85 Correct 913 ms 49580 KB Output is correct
86 Correct 244 ms 24032 KB Output is correct
87 Correct 0 ms 376 KB Output is correct