Submission #222818

# Submission time Handle Problem Language Result Execution time Memory
222818 2020-04-14T04:07:06 Z atoiz Strange Device (APIO19_strange_device) C++14
100 / 100
938 ms 75900 KB
/*input
2 16 13
2 5
18 18
*/

#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

const int64_t INF = 2e18;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	int64_t A, B;
	cin >> N >> A >> B;

	int64_t M = A / __gcd(A, B + 1);
	M = (INF / M < B ? INF : B * M);

	map<int64_t, int> vals;
	while (N--) {
		int64_t L, R;
		cin >> L >> R;
		++R; 

		if (R - L >= M) return cout << M << endl, 0;
		L %= M, R %= M;

		if (L < R) ++vals[L], --vals[R];
		else ++vals[0], --vals[R], ++vals[L], --vals[M];
	}

	int64_t last = 0, cnt = 0;
	int cur = 0;
	for (auto p : vals) {
		cnt += (cur > 0) * (p.first - last);
		last = p.first;
		cur += p.second;
	}
	cout << cnt << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 1408 KB Output is correct
3 Correct 12 ms 1408 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 85 ms 8184 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 362 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 816 ms 63072 KB Output is correct
3 Correct 868 ms 64504 KB Output is correct
4 Correct 926 ms 75768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 816 ms 63072 KB Output is correct
3 Correct 868 ms 64504 KB Output is correct
4 Correct 926 ms 75768 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 862 ms 75680 KB Output is correct
7 Correct 873 ms 75896 KB Output is correct
8 Correct 855 ms 75768 KB Output is correct
9 Correct 938 ms 75780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 816 ms 63072 KB Output is correct
3 Correct 868 ms 64504 KB Output is correct
4 Correct 926 ms 75768 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 78 ms 10360 KB Output is correct
7 Correct 77 ms 10360 KB Output is correct
8 Correct 80 ms 10276 KB Output is correct
9 Correct 84 ms 10360 KB Output is correct
10 Correct 82 ms 10360 KB Output is correct
11 Correct 79 ms 10360 KB Output is correct
12 Correct 79 ms 10360 KB Output is correct
13 Correct 93 ms 10488 KB Output is correct
14 Correct 78 ms 10360 KB Output is correct
15 Correct 88 ms 10360 KB Output is correct
16 Correct 85 ms 10360 KB Output is correct
17 Correct 83 ms 10360 KB Output is correct
18 Correct 820 ms 75744 KB Output is correct
19 Correct 890 ms 75888 KB Output is correct
20 Correct 921 ms 75900 KB Output is correct
21 Correct 88 ms 10488 KB Output is correct
22 Correct 85 ms 10360 KB Output is correct
23 Correct 159 ms 12920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 89 ms 8056 KB Output is correct
3 Correct 94 ms 8184 KB Output is correct
4 Correct 889 ms 64404 KB Output is correct
5 Correct 93 ms 8056 KB Output is correct
6 Correct 91 ms 8056 KB Output is correct
7 Correct 95 ms 8056 KB Output is correct
8 Correct 86 ms 8056 KB Output is correct
9 Correct 91 ms 8056 KB Output is correct
10 Correct 84 ms 8060 KB Output is correct
11 Correct 84 ms 8056 KB Output is correct
12 Correct 83 ms 8056 KB Output is correct
13 Correct 98 ms 8056 KB Output is correct
14 Correct 924 ms 64524 KB Output is correct
15 Correct 77 ms 8056 KB Output is correct
16 Correct 818 ms 75732 KB Output is correct
17 Correct 831 ms 75768 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 1408 KB Output is correct
3 Correct 12 ms 1408 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 85 ms 8184 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 362 ms 3320 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 816 ms 63072 KB Output is correct
31 Correct 868 ms 64504 KB Output is correct
32 Correct 926 ms 75768 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 862 ms 75680 KB Output is correct
35 Correct 873 ms 75896 KB Output is correct
36 Correct 855 ms 75768 KB Output is correct
37 Correct 938 ms 75780 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 78 ms 10360 KB Output is correct
40 Correct 77 ms 10360 KB Output is correct
41 Correct 80 ms 10276 KB Output is correct
42 Correct 84 ms 10360 KB Output is correct
43 Correct 82 ms 10360 KB Output is correct
44 Correct 79 ms 10360 KB Output is correct
45 Correct 79 ms 10360 KB Output is correct
46 Correct 93 ms 10488 KB Output is correct
47 Correct 78 ms 10360 KB Output is correct
48 Correct 88 ms 10360 KB Output is correct
49 Correct 85 ms 10360 KB Output is correct
50 Correct 83 ms 10360 KB Output is correct
51 Correct 820 ms 75744 KB Output is correct
52 Correct 890 ms 75888 KB Output is correct
53 Correct 921 ms 75900 KB Output is correct
54 Correct 88 ms 10488 KB Output is correct
55 Correct 85 ms 10360 KB Output is correct
56 Correct 159 ms 12920 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 89 ms 8056 KB Output is correct
59 Correct 94 ms 8184 KB Output is correct
60 Correct 889 ms 64404 KB Output is correct
61 Correct 93 ms 8056 KB Output is correct
62 Correct 91 ms 8056 KB Output is correct
63 Correct 95 ms 8056 KB Output is correct
64 Correct 86 ms 8056 KB Output is correct
65 Correct 91 ms 8056 KB Output is correct
66 Correct 84 ms 8060 KB Output is correct
67 Correct 84 ms 8056 KB Output is correct
68 Correct 83 ms 8056 KB Output is correct
69 Correct 98 ms 8056 KB Output is correct
70 Correct 924 ms 64524 KB Output is correct
71 Correct 77 ms 8056 KB Output is correct
72 Correct 818 ms 75732 KB Output is correct
73 Correct 831 ms 75768 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 12 ms 1408 KB Output is correct
80 Correct 924 ms 75772 KB Output is correct
81 Correct 908 ms 75864 KB Output is correct
82 Correct 926 ms 75768 KB Output is correct
83 Correct 927 ms 75704 KB Output is correct
84 Correct 938 ms 75760 KB Output is correct
85 Correct 906 ms 75900 KB Output is correct
86 Correct 161 ms 12920 KB Output is correct
87 Correct 5 ms 384 KB Output is correct