Submission #341317

# Submission time Handle Problem Language Result Execution time Memory
341317 2020-12-29T13:12:24 Z ogibogi2004 Strange Device (APIO19_strange_device) C++14
100 / 100
2003 ms 116332 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2e18;
ll n;
ll a,b;
map<ll,ll>mp;
ll l[2000002];
ll r[2000002];
int main()
{
	cin>>n;cin>>a>>b;
	ll d=__gcd(a,b+1);
	ll m;
	if(b>INF/(a/d))
	{
		m=INF;
	}
	else m=(a/d)*b;
	//cout<<m<<endl;
	for(ll i=1;i<=n;i++)
	{
		cin>>l[i]>>r[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if((r[i]-l[i]+1)>=m)
		{
			cout<<m<<endl;
			return 0;
		}
		ll l1=l[i]%m;
		ll r1=(r[i]+1)%m;
		//cout<<l1<<" "<<r1<<endl;
		if(l1<=r1)
		{
			mp[l1]++;
			mp[r1]--;
		}
		else
		{
			mp[0]++;
			mp[r1]--;
			mp[l1]++;
			mp[m]--;
		}
	}
	ll ans=0,cur=0,last=-1,cur1=0;
	for(auto xd:mp)
	{
		//if(xd.first==m)continue;
		cur+=xd.second;
		//cout<<"_"<<xd.first<<" "<<cur1<<endl;
		if(cur1>0)
		{
			ans+=xd.first-last;
		}
		last=xd.first;
		cur1=cur;
	}
	cout<<min(m,ans)<<endl;
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 17 ms 1516 KB Output is correct
3 Correct 17 ms 1516 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 364 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 17 ms 1644 KB Output is correct
17 Correct 177 ms 11884 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 1111 ms 41180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1761 ms 85888 KB Output is correct
3 Correct 1827 ms 115824 KB Output is correct
4 Correct 1840 ms 116004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1761 ms 85888 KB Output is correct
3 Correct 1827 ms 115824 KB Output is correct
4 Correct 1840 ms 116004 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1814 ms 115908 KB Output is correct
7 Correct 1830 ms 115856 KB Output is correct
8 Correct 1782 ms 115948 KB Output is correct
9 Correct 1844 ms 116016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1761 ms 85888 KB Output is correct
3 Correct 1827 ms 115824 KB Output is correct
4 Correct 1840 ms 116004 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 168 ms 12016 KB Output is correct
7 Correct 169 ms 11884 KB Output is correct
8 Correct 171 ms 12012 KB Output is correct
9 Correct 174 ms 11884 KB Output is correct
10 Correct 173 ms 11884 KB Output is correct
11 Correct 173 ms 11884 KB Output is correct
12 Correct 173 ms 11884 KB Output is correct
13 Correct 178 ms 11884 KB Output is correct
14 Correct 169 ms 11884 KB Output is correct
15 Correct 192 ms 11884 KB Output is correct
16 Correct 175 ms 11884 KB Output is correct
17 Correct 175 ms 11884 KB Output is correct
18 Correct 1765 ms 115948 KB Output is correct
19 Correct 1814 ms 115792 KB Output is correct
20 Correct 1854 ms 116332 KB Output is correct
21 Correct 172 ms 11896 KB Output is correct
22 Correct 178 ms 11884 KB Output is correct
23 Correct 484 ms 18412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 193 ms 11884 KB Output is correct
3 Correct 176 ms 11884 KB Output is correct
4 Correct 1860 ms 115864 KB Output is correct
5 Correct 180 ms 11884 KB Output is correct
6 Correct 180 ms 11848 KB Output is correct
7 Correct 180 ms 11884 KB Output is correct
8 Correct 177 ms 11840 KB Output is correct
9 Correct 178 ms 12012 KB Output is correct
10 Correct 172 ms 11868 KB Output is correct
11 Correct 170 ms 11884 KB Output is correct
12 Correct 180 ms 11884 KB Output is correct
13 Correct 185 ms 11884 KB Output is correct
14 Correct 1953 ms 115980 KB Output is correct
15 Correct 169 ms 11884 KB Output is correct
16 Correct 1767 ms 116080 KB Output is correct
17 Correct 1760 ms 116284 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 17 ms 1516 KB Output is correct
3 Correct 17 ms 1516 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 364 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 17 ms 1644 KB Output is correct
17 Correct 177 ms 11884 KB Output is correct
18 Correct 1 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 1 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 1111 ms 41180 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1761 ms 85888 KB Output is correct
31 Correct 1827 ms 115824 KB Output is correct
32 Correct 1840 ms 116004 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1814 ms 115908 KB Output is correct
35 Correct 1830 ms 115856 KB Output is correct
36 Correct 1782 ms 115948 KB Output is correct
37 Correct 1844 ms 116016 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 168 ms 12016 KB Output is correct
40 Correct 169 ms 11884 KB Output is correct
41 Correct 171 ms 12012 KB Output is correct
42 Correct 174 ms 11884 KB Output is correct
43 Correct 173 ms 11884 KB Output is correct
44 Correct 173 ms 11884 KB Output is correct
45 Correct 173 ms 11884 KB Output is correct
46 Correct 178 ms 11884 KB Output is correct
47 Correct 169 ms 11884 KB Output is correct
48 Correct 192 ms 11884 KB Output is correct
49 Correct 175 ms 11884 KB Output is correct
50 Correct 175 ms 11884 KB Output is correct
51 Correct 1765 ms 115948 KB Output is correct
52 Correct 1814 ms 115792 KB Output is correct
53 Correct 1854 ms 116332 KB Output is correct
54 Correct 172 ms 11896 KB Output is correct
55 Correct 178 ms 11884 KB Output is correct
56 Correct 484 ms 18412 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 193 ms 11884 KB Output is correct
59 Correct 176 ms 11884 KB Output is correct
60 Correct 1860 ms 115864 KB Output is correct
61 Correct 180 ms 11884 KB Output is correct
62 Correct 180 ms 11848 KB Output is correct
63 Correct 180 ms 11884 KB Output is correct
64 Correct 177 ms 11840 KB Output is correct
65 Correct 178 ms 12012 KB Output is correct
66 Correct 172 ms 11868 KB Output is correct
67 Correct 170 ms 11884 KB Output is correct
68 Correct 180 ms 11884 KB Output is correct
69 Correct 185 ms 11884 KB Output is correct
70 Correct 1953 ms 115980 KB Output is correct
71 Correct 169 ms 11884 KB Output is correct
72 Correct 1767 ms 116080 KB Output is correct
73 Correct 1760 ms 116284 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 17 ms 1516 KB Output is correct
80 Correct 1890 ms 115944 KB Output is correct
81 Correct 1877 ms 116200 KB Output is correct
82 Correct 1952 ms 116072 KB Output is correct
83 Correct 1942 ms 116072 KB Output is correct
84 Correct 2003 ms 115852 KB Output is correct
85 Correct 1906 ms 115864 KB Output is correct
86 Correct 480 ms 18156 KB Output is correct
87 Correct 1 ms 364 KB Output is correct