Submission #320989

# Submission time Handle Problem Language Result Execution time Memory
320989 2020-11-10T12:48:40 Z Drew_ Strange Device (APIO19_strange_device) C++14
100 / 100
747 ms 86344 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	ll n, a, b;
	cin >> n >> a >> b;

	vector<pl> v(n);
	for (pl &x : v)
		cin >> x.f1 >> x.s2;

	ll gcd = __gcd(a, b+1);
	if (v.back().s2 / b < a / gcd)
	{
		ll res = 0;
		for (pl x : v)
			res += (x.s2 - x.f1 + 1);
		cout << res << '\n';	
		return 0;
	}
	ll mod = (a/gcd) * b;
	
	vector<pl> range; //first: duration, second: state
	for (pl x : v)
	{
		if (x.s2 - x.f1 + 1 >= mod)
		{
			cout << mod << '\n';
			return 0;
		}

		ll l = x.f1 % mod;
		ll r = x.s2 % mod;

		if (l <= r)
		{
			range.pb({l, 1}); 
			range.pb({r+1, -1});
		}
		else
		{
			range.pb({l, 1});
			range.pb({mod, -1});
			range.pb({0, 1});
			range.pb({r+1, -1});
		}
	}
	sort(range.begin(), range.end());

	//for (auto x : range)
	//{
	//	cout << "-> " << x.f1 << " " << x.s2 << '\n';
	//}

	ll ctr = 0;
	ll res = 0;
	for (int i = 0; i+1 < range.size(); ++i)
	{
		ctr += range[i].s2;
		if (ctr > 0) res += (range[i+1].f1 - range[i].f1);
	}
	cout << res << '\n';
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:75:22: 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]
   75 |  for (int i = 0; i+1 < range.size(); ++i)
      |                  ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 6 ms 1264 KB Output is correct
3 Correct 6 ms 1264 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 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 6 ms 1520 KB Output is correct
17 Correct 64 ms 9820 KB Output is correct
18 Correct 0 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 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 409 ms 49224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 572 ms 49348 KB Output is correct
3 Correct 603 ms 49808 KB Output is correct
4 Correct 578 ms 86212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 572 ms 49348 KB Output is correct
3 Correct 603 ms 49808 KB Output is correct
4 Correct 578 ms 86212 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 599 ms 86316 KB Output is correct
7 Correct 585 ms 86216 KB Output is correct
8 Correct 587 ms 86344 KB Output is correct
9 Correct 699 ms 86216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 572 ms 49348 KB Output is correct
3 Correct 603 ms 49808 KB Output is correct
4 Correct 578 ms 86212 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 56 ms 9820 KB Output is correct
7 Correct 59 ms 9820 KB Output is correct
8 Correct 56 ms 9820 KB Output is correct
9 Correct 56 ms 9820 KB Output is correct
10 Correct 54 ms 9820 KB Output is correct
11 Correct 59 ms 9820 KB Output is correct
12 Correct 56 ms 9896 KB Output is correct
13 Correct 61 ms 9820 KB Output is correct
14 Correct 57 ms 9820 KB Output is correct
15 Correct 64 ms 9820 KB Output is correct
16 Correct 64 ms 9948 KB Output is correct
17 Correct 59 ms 9924 KB Output is correct
18 Correct 601 ms 86236 KB Output is correct
19 Correct 573 ms 86244 KB Output is correct
20 Correct 713 ms 86148 KB Output is correct
21 Correct 65 ms 9820 KB Output is correct
22 Correct 51 ms 9908 KB Output is correct
23 Correct 164 ms 34900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 62 ms 8672 KB Output is correct
3 Correct 63 ms 8668 KB Output is correct
4 Correct 735 ms 51748 KB Output is correct
5 Correct 75 ms 9180 KB Output is correct
6 Correct 61 ms 9200 KB Output is correct
7 Correct 61 ms 9052 KB Output is correct
8 Correct 69 ms 9052 KB Output is correct
9 Correct 59 ms 9052 KB Output is correct
10 Correct 66 ms 9052 KB Output is correct
11 Correct 62 ms 9052 KB Output is correct
12 Correct 55 ms 9052 KB Output is correct
13 Correct 64 ms 9052 KB Output is correct
14 Correct 685 ms 51908 KB Output is correct
15 Correct 70 ms 9564 KB Output is correct
16 Correct 544 ms 49844 KB Output is correct
17 Correct 569 ms 49856 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 6 ms 1264 KB Output is correct
3 Correct 6 ms 1264 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 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 6 ms 1520 KB Output is correct
17 Correct 64 ms 9820 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 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 409 ms 49224 KB Output is correct
29 Correct 1 ms 620 KB Output is correct
30 Correct 572 ms 49348 KB Output is correct
31 Correct 603 ms 49808 KB Output is correct
32 Correct 578 ms 86212 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 599 ms 86316 KB Output is correct
35 Correct 585 ms 86216 KB Output is correct
36 Correct 587 ms 86344 KB Output is correct
37 Correct 699 ms 86216 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 56 ms 9820 KB Output is correct
40 Correct 59 ms 9820 KB Output is correct
41 Correct 56 ms 9820 KB Output is correct
42 Correct 56 ms 9820 KB Output is correct
43 Correct 54 ms 9820 KB Output is correct
44 Correct 59 ms 9820 KB Output is correct
45 Correct 56 ms 9896 KB Output is correct
46 Correct 61 ms 9820 KB Output is correct
47 Correct 57 ms 9820 KB Output is correct
48 Correct 64 ms 9820 KB Output is correct
49 Correct 64 ms 9948 KB Output is correct
50 Correct 59 ms 9924 KB Output is correct
51 Correct 601 ms 86236 KB Output is correct
52 Correct 573 ms 86244 KB Output is correct
53 Correct 713 ms 86148 KB Output is correct
54 Correct 65 ms 9820 KB Output is correct
55 Correct 51 ms 9908 KB Output is correct
56 Correct 164 ms 34900 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 62 ms 8672 KB Output is correct
59 Correct 63 ms 8668 KB Output is correct
60 Correct 735 ms 51748 KB Output is correct
61 Correct 75 ms 9180 KB Output is correct
62 Correct 61 ms 9200 KB Output is correct
63 Correct 61 ms 9052 KB Output is correct
64 Correct 69 ms 9052 KB Output is correct
65 Correct 59 ms 9052 KB Output is correct
66 Correct 66 ms 9052 KB Output is correct
67 Correct 62 ms 9052 KB Output is correct
68 Correct 55 ms 9052 KB Output is correct
69 Correct 64 ms 9052 KB Output is correct
70 Correct 685 ms 51908 KB Output is correct
71 Correct 70 ms 9564 KB Output is correct
72 Correct 544 ms 49844 KB Output is correct
73 Correct 569 ms 49856 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 6 ms 1520 KB Output is correct
80 Correct 739 ms 86164 KB Output is correct
81 Correct 747 ms 86308 KB Output is correct
82 Correct 698 ms 86100 KB Output is correct
83 Correct 689 ms 86092 KB Output is correct
84 Correct 686 ms 85944 KB Output is correct
85 Correct 678 ms 86224 KB Output is correct
86 Correct 164 ms 34772 KB Output is correct
87 Correct 1 ms 364 KB Output is correct