Submission #572383

# Submission time Handle Problem Language Result Execution time Memory
572383 2022-06-04T10:13:22 Z CpDark Strange Device (APIO19_strange_device) C++14
100 / 100
509 ms 69036 KB
#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;

ll A, B;
inline pii getTime(ll t) {
	ll x = (t + (t / B)) % A;
	ll y = t % B;
	return { x,y };
}

inline void pushTime(pii p, ll mod, vp &points) {

	if (p.first % mod <= p.second % mod) {
		points.push_back({ p.first % mod, p.second % mod });
	}
	else {
		points.push_back({ p.first % mod, mod - 1 });
		points.push_back({ 0, p.second % mod });
	}
	
}

ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
const ll inf = 1e18 + 1;

int main() {
	fastInput;
	int n;
	cin >> n >> A >> B;

	ll mod = inf;

	A /= gcd(A, B + 1);
	if (A <= inf / B) {
		mod = A * B;
	}
	vp times(n);
	vp points;
	ll l, r;
	for (int i = 0; i < n; i++) {
		cin >> l >> r;
		times[i] = {l,r};
		if (r - l + 1 >= mod) {
			cout << mod;
			return 0;
		}
		pushTime(times[i], mod, points);
	}
	
	sort(points.begin(), points.end());
	ll count = 0;
	ll last = points[0].second;
	ll start = points[0].first;
	for (int i = 0; i < points.size(); i++) {
		if (points[i].first > last) {
			ll amount = last - start + 1;
			start = points[i].first;
			count += amount;
			last = points[i].second;
		}
		else last = max(last, points[i].second);
		
	}
	ll amount = last - start + 1;
	count += amount;
	cout << count;

	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:72:20: 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]
   72 |  for (int i = 0; i < points.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 42 ms 4048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 324 ms 32408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 408 ms 32448 KB Output is correct
3 Correct 390 ms 32496 KB Output is correct
4 Correct 396 ms 32512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 408 ms 32448 KB Output is correct
3 Correct 390 ms 32496 KB Output is correct
4 Correct 396 ms 32512 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 418 ms 32436 KB Output is correct
7 Correct 403 ms 32432 KB Output is correct
8 Correct 382 ms 32552 KB Output is correct
9 Correct 434 ms 32504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 408 ms 32448 KB Output is correct
3 Correct 390 ms 32496 KB Output is correct
4 Correct 396 ms 32512 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 38 ms 4068 KB Output is correct
7 Correct 41 ms 4040 KB Output is correct
8 Correct 37 ms 4080 KB Output is correct
9 Correct 39 ms 3984 KB Output is correct
10 Correct 38 ms 4076 KB Output is correct
11 Correct 49 ms 3964 KB Output is correct
12 Correct 37 ms 4072 KB Output is correct
13 Correct 41 ms 4080 KB Output is correct
14 Correct 36 ms 4028 KB Output is correct
15 Correct 40 ms 4048 KB Output is correct
16 Correct 44 ms 4064 KB Output is correct
17 Correct 42 ms 3956 KB Output is correct
18 Correct 387 ms 32432 KB Output is correct
19 Correct 401 ms 32500 KB Output is correct
20 Correct 415 ms 32480 KB Output is correct
21 Correct 52 ms 4040 KB Output is correct
22 Correct 43 ms 4000 KB Output is correct
23 Correct 118 ms 14004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 40 ms 3996 KB Output is correct
3 Correct 40 ms 4100 KB Output is correct
4 Correct 491 ms 32552 KB Output is correct
5 Correct 40 ms 4044 KB Output is correct
6 Correct 39 ms 4068 KB Output is correct
7 Correct 42 ms 4012 KB Output is correct
8 Correct 43 ms 3960 KB Output is correct
9 Correct 41 ms 4040 KB Output is correct
10 Correct 40 ms 4024 KB Output is correct
11 Correct 40 ms 3996 KB Output is correct
12 Correct 36 ms 4092 KB Output is correct
13 Correct 39 ms 3996 KB Output is correct
14 Correct 464 ms 32480 KB Output is correct
15 Correct 42 ms 4044 KB Output is correct
16 Correct 374 ms 32432 KB Output is correct
17 Correct 500 ms 32524 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 42 ms 4048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 324 ms 32408 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 408 ms 32448 KB Output is correct
31 Correct 390 ms 32496 KB Output is correct
32 Correct 396 ms 32512 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 418 ms 32436 KB Output is correct
35 Correct 403 ms 32432 KB Output is correct
36 Correct 382 ms 32552 KB Output is correct
37 Correct 434 ms 32504 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 38 ms 4068 KB Output is correct
40 Correct 41 ms 4040 KB Output is correct
41 Correct 37 ms 4080 KB Output is correct
42 Correct 39 ms 3984 KB Output is correct
43 Correct 38 ms 4076 KB Output is correct
44 Correct 49 ms 3964 KB Output is correct
45 Correct 37 ms 4072 KB Output is correct
46 Correct 41 ms 4080 KB Output is correct
47 Correct 36 ms 4028 KB Output is correct
48 Correct 40 ms 4048 KB Output is correct
49 Correct 44 ms 4064 KB Output is correct
50 Correct 42 ms 3956 KB Output is correct
51 Correct 387 ms 32432 KB Output is correct
52 Correct 401 ms 32500 KB Output is correct
53 Correct 415 ms 32480 KB Output is correct
54 Correct 52 ms 4040 KB Output is correct
55 Correct 43 ms 4000 KB Output is correct
56 Correct 118 ms 14004 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 40 ms 3996 KB Output is correct
59 Correct 40 ms 4100 KB Output is correct
60 Correct 491 ms 32552 KB Output is correct
61 Correct 40 ms 4044 KB Output is correct
62 Correct 39 ms 4068 KB Output is correct
63 Correct 42 ms 4012 KB Output is correct
64 Correct 43 ms 3960 KB Output is correct
65 Correct 41 ms 4040 KB Output is correct
66 Correct 40 ms 4024 KB Output is correct
67 Correct 40 ms 3996 KB Output is correct
68 Correct 36 ms 4092 KB Output is correct
69 Correct 39 ms 3996 KB Output is correct
70 Correct 464 ms 32480 KB Output is correct
71 Correct 42 ms 4044 KB Output is correct
72 Correct 374 ms 32432 KB Output is correct
73 Correct 500 ms 32524 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 324 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 312 KB Output is correct
79 Correct 4 ms 1236 KB Output is correct
80 Correct 477 ms 68928 KB Output is correct
81 Correct 496 ms 69036 KB Output is correct
82 Correct 509 ms 68988 KB Output is correct
83 Correct 465 ms 68872 KB Output is correct
84 Correct 447 ms 68928 KB Output is correct
85 Correct 453 ms 68912 KB Output is correct
86 Correct 131 ms 23820 KB Output is correct
87 Correct 1 ms 316 KB Output is correct