Submission #171757

# Submission time Handle Problem Language Result Execution time Memory
171757 2019-12-30T10:03:06 Z Sensei Strange Device (APIO19_strange_device) C++17
100 / 100
689 ms 31508 KB
/*
	DATE:		2019-12-30 11:10:15
	NAME:		
	PROBLEM:	APIO19_strange_device
*/
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;
const long long LLINF = 1e18 + 100;

class Segment {
public:
	long long l, r;
	Segment() {}
	Segment(long long x, long long y) {
		l = x;
		r = y;
	}
};

long long f(long long x, long long y) {
	if (x / __gcd(x, y + 1) > LLINF / y) {
		return LLINF;
	}

	return x / __gcd(x, y + 1) * y;
}

int main() {
	int n;
	cin >> n;

	long long A, B;
	cin >> A >> B;

	long long C = f(A, B);

	vector<Segment> segments;

	for (int i = 1; i <= n; i++) {
		Segment segment;
		scanf("%lld %lld", &segment.l, &segment.r);

		if (segment.r - segment.l + 1 >= C) {
			cout << C << "\n";
			return 0;
		}

		segment.l %= C;
		segment.r %= C;

		if (segment.l <= segment.r) {
			segments.push_back(segment);
		}
		else {
			segments.push_back(Segment(0, segment.r));
			segments.push_back(Segment(segment.l, C - 1));
		}
	}

	sort(segments.begin(), segments.end(), [](Segment x, Segment y) {
		if (x.l == y.l) {
			return x.r < y.r;
		}

		return x.l < y.l;
	});

	long long lastr = -1;
	long long ans = 0;

	for (int i = 0; i < segments.size(); i++) {
		if (segments[i].l > lastr) {
			lastr = segments[i].l - 1;
		}

		if (segments[i].r > lastr) {
			ans += segments[i].r - lastr;
			lastr = segments[i].r;
		}
	}

	cout << ans << "\n";

	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < segments.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &segment.l, &segment.r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 9 ms 632 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 65 ms 2540 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 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 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 435 ms 17048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 565 ms 16944 KB Output is correct
3 Correct 574 ms 16820 KB Output is correct
4 Correct 560 ms 21736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 565 ms 16944 KB Output is correct
3 Correct 574 ms 16820 KB Output is correct
4 Correct 560 ms 21736 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 573 ms 18244 KB Output is correct
7 Correct 590 ms 20412 KB Output is correct
8 Correct 572 ms 20776 KB Output is correct
9 Correct 649 ms 18900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 360 KB Output is correct
2 Correct 565 ms 16944 KB Output is correct
3 Correct 574 ms 16820 KB Output is correct
4 Correct 560 ms 21736 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 58 ms 5736 KB Output is correct
7 Correct 66 ms 5700 KB Output is correct
8 Correct 56 ms 5732 KB Output is correct
9 Correct 59 ms 5224 KB Output is correct
10 Correct 58 ms 5092 KB Output is correct
11 Correct 60 ms 5228 KB Output is correct
12 Correct 56 ms 5732 KB Output is correct
13 Correct 65 ms 5224 KB Output is correct
14 Correct 66 ms 5220 KB Output is correct
15 Correct 123 ms 5712 KB Output is correct
16 Correct 66 ms 5708 KB Output is correct
17 Correct 61 ms 5856 KB Output is correct
18 Correct 598 ms 18912 KB Output is correct
19 Correct 562 ms 19212 KB Output is correct
20 Correct 651 ms 18896 KB Output is correct
21 Correct 63 ms 5736 KB Output is correct
22 Correct 54 ms 5748 KB Output is correct
23 Correct 206 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 62 ms 2796 KB Output is correct
3 Correct 62 ms 2796 KB Output is correct
4 Correct 651 ms 20428 KB Output is correct
5 Correct 61 ms 2796 KB Output is correct
6 Correct 61 ms 2796 KB Output is correct
7 Correct 62 ms 2796 KB Output is correct
8 Correct 64 ms 2796 KB Output is correct
9 Correct 60 ms 2796 KB Output is correct
10 Correct 61 ms 2792 KB Output is correct
11 Correct 62 ms 2920 KB Output is correct
12 Correct 52 ms 2796 KB Output is correct
13 Correct 62 ms 2796 KB Output is correct
14 Correct 654 ms 23196 KB Output is correct
15 Correct 62 ms 2796 KB Output is correct
16 Correct 579 ms 22516 KB Output is correct
17 Correct 567 ms 20156 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 9 ms 632 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 65 ms 2540 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 435 ms 17048 KB Output is correct
29 Correct 2 ms 360 KB Output is correct
30 Correct 565 ms 16944 KB Output is correct
31 Correct 574 ms 16820 KB Output is correct
32 Correct 560 ms 21736 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 573 ms 18244 KB Output is correct
35 Correct 590 ms 20412 KB Output is correct
36 Correct 572 ms 20776 KB Output is correct
37 Correct 649 ms 18900 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 58 ms 5736 KB Output is correct
40 Correct 66 ms 5700 KB Output is correct
41 Correct 56 ms 5732 KB Output is correct
42 Correct 59 ms 5224 KB Output is correct
43 Correct 58 ms 5092 KB Output is correct
44 Correct 60 ms 5228 KB Output is correct
45 Correct 56 ms 5732 KB Output is correct
46 Correct 65 ms 5224 KB Output is correct
47 Correct 66 ms 5220 KB Output is correct
48 Correct 123 ms 5712 KB Output is correct
49 Correct 66 ms 5708 KB Output is correct
50 Correct 61 ms 5856 KB Output is correct
51 Correct 598 ms 18912 KB Output is correct
52 Correct 562 ms 19212 KB Output is correct
53 Correct 651 ms 18896 KB Output is correct
54 Correct 63 ms 5736 KB Output is correct
55 Correct 54 ms 5748 KB Output is correct
56 Correct 206 ms 11648 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 62 ms 2796 KB Output is correct
59 Correct 62 ms 2796 KB Output is correct
60 Correct 651 ms 20428 KB Output is correct
61 Correct 61 ms 2796 KB Output is correct
62 Correct 61 ms 2796 KB Output is correct
63 Correct 62 ms 2796 KB Output is correct
64 Correct 64 ms 2796 KB Output is correct
65 Correct 60 ms 2796 KB Output is correct
66 Correct 61 ms 2792 KB Output is correct
67 Correct 62 ms 2920 KB Output is correct
68 Correct 52 ms 2796 KB Output is correct
69 Correct 62 ms 2796 KB Output is correct
70 Correct 654 ms 23196 KB Output is correct
71 Correct 62 ms 2796 KB Output is correct
72 Correct 579 ms 22516 KB Output is correct
73 Correct 567 ms 20156 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 256 KB Output is correct
76 Correct 2 ms 364 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 7 ms 1016 KB Output is correct
80 Correct 675 ms 31476 KB Output is correct
81 Correct 655 ms 31440 KB Output is correct
82 Correct 637 ms 31312 KB Output is correct
83 Correct 652 ms 31508 KB Output is correct
84 Correct 642 ms 31396 KB Output is correct
85 Correct 689 ms 31312 KB Output is correct
86 Correct 210 ms 18492 KB Output is correct
87 Correct 3 ms 376 KB Output is correct