답안 #445801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445801 2021-07-19T15:36:49 Z nonsensenonsense1 이상한 기계 (APIO19_strange_device) C++17
100 / 100
587 ms 30032 KB
#include <cstdio>
#include <vector>
#include <algorithm>

long long gcd(long long a, long long b) 
{
	while (a && b) {
		if (a > b) a %= b;
		else b %= a;
	}
	return a + b;
}

int n;
long long a, b, l, r;

int main() 
{
	scanf("%d%lld%lld", &n, &a, &b);
	long long d = b % a + 1, k = a / gcd(a, d), p;
	if ((~((long long)1 << 63) >> 1) / k < b) p = ~((long long)1 << 63);
	else p = k * b;
	std::vector<std::pair<long long, long long> > s;
	for (int i = 0; i < n; ++i) {
		scanf("%lld%lld", &l, &r);
		if (r - l + 1 >= p) {
			printf("%lld\n", p);
			return 0;
		}
		l %= p;
		r %= p;
		if (l <= r) s.push_back(std::make_pair(l, r));
		else {
			s.push_back(std::make_pair(0, r));
			s.push_back(std::make_pair(l, p - 1));
		}
	}
	std::sort(s.begin(), s.end());
	long long ans = 0, l = 0, r = -1;
	for (int i = 0; i < (int)s.size(); ++i) {
		if (s[i].first <= r) {
			ans += std::max((long long)0, s[i].second - r);
			r = std::max(r, s[i].second);
		}
		else {
			ans += s[i].second - s[i].first + 1;
			l = s[i].first;
			r = s[i].second;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:39:21: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   39 |  long long ans = 0, l = 0, r = -1;
      |                     ^
strange_device.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d%lld%lld", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 6 ms 972 KB Output is correct
3 Correct 6 ms 1036 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 55 ms 2948 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 363 ms 16920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 506 ms 16756 KB Output is correct
3 Correct 490 ms 16936 KB Output is correct
4 Correct 492 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 506 ms 16756 KB Output is correct
3 Correct 490 ms 16936 KB Output is correct
4 Correct 492 ms 17236 KB Output is correct
5 Correct 0 ms 276 KB Output is correct
6 Correct 502 ms 17180 KB Output is correct
7 Correct 503 ms 17080 KB Output is correct
8 Correct 496 ms 17112 KB Output is correct
9 Correct 554 ms 17180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 506 ms 16756 KB Output is correct
3 Correct 490 ms 16936 KB Output is correct
4 Correct 492 ms 17236 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 48 ms 2744 KB Output is correct
7 Correct 53 ms 2796 KB Output is correct
8 Correct 48 ms 2808 KB Output is correct
9 Correct 49 ms 2748 KB Output is correct
10 Correct 55 ms 2816 KB Output is correct
11 Correct 51 ms 2716 KB Output is correct
12 Correct 47 ms 2720 KB Output is correct
13 Correct 52 ms 2748 KB Output is correct
14 Correct 49 ms 2688 KB Output is correct
15 Correct 56 ms 2740 KB Output is correct
16 Correct 53 ms 2744 KB Output is correct
17 Correct 49 ms 2676 KB Output is correct
18 Correct 516 ms 17096 KB Output is correct
19 Correct 492 ms 17080 KB Output is correct
20 Correct 550 ms 17312 KB Output is correct
21 Correct 53 ms 2752 KB Output is correct
22 Correct 47 ms 2772 KB Output is correct
23 Correct 153 ms 8832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 55 ms 2796 KB Output is correct
3 Correct 53 ms 2788 KB Output is correct
4 Correct 587 ms 16816 KB Output is correct
5 Correct 52 ms 2744 KB Output is correct
6 Correct 53 ms 2736 KB Output is correct
7 Correct 52 ms 2704 KB Output is correct
8 Correct 53 ms 2668 KB Output is correct
9 Correct 51 ms 2540 KB Output is correct
10 Correct 54 ms 2676 KB Output is correct
11 Correct 53 ms 2596 KB Output is correct
12 Correct 48 ms 2660 KB Output is correct
13 Correct 53 ms 2616 KB Output is correct
14 Correct 553 ms 16756 KB Output is correct
15 Correct 52 ms 2616 KB Output is correct
16 Correct 496 ms 16968 KB Output is correct
17 Correct 494 ms 16924 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 6 ms 972 KB Output is correct
3 Correct 6 ms 1036 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 55 ms 2948 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 363 ms 16920 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 506 ms 16756 KB Output is correct
31 Correct 490 ms 16936 KB Output is correct
32 Correct 492 ms 17236 KB Output is correct
33 Correct 0 ms 276 KB Output is correct
34 Correct 502 ms 17180 KB Output is correct
35 Correct 503 ms 17080 KB Output is correct
36 Correct 496 ms 17112 KB Output is correct
37 Correct 554 ms 17180 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 48 ms 2744 KB Output is correct
40 Correct 53 ms 2796 KB Output is correct
41 Correct 48 ms 2808 KB Output is correct
42 Correct 49 ms 2748 KB Output is correct
43 Correct 55 ms 2816 KB Output is correct
44 Correct 51 ms 2716 KB Output is correct
45 Correct 47 ms 2720 KB Output is correct
46 Correct 52 ms 2748 KB Output is correct
47 Correct 49 ms 2688 KB Output is correct
48 Correct 56 ms 2740 KB Output is correct
49 Correct 53 ms 2744 KB Output is correct
50 Correct 49 ms 2676 KB Output is correct
51 Correct 516 ms 17096 KB Output is correct
52 Correct 492 ms 17080 KB Output is correct
53 Correct 550 ms 17312 KB Output is correct
54 Correct 53 ms 2752 KB Output is correct
55 Correct 47 ms 2772 KB Output is correct
56 Correct 153 ms 8832 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 55 ms 2796 KB Output is correct
59 Correct 53 ms 2788 KB Output is correct
60 Correct 587 ms 16816 KB Output is correct
61 Correct 52 ms 2744 KB Output is correct
62 Correct 53 ms 2736 KB Output is correct
63 Correct 52 ms 2704 KB Output is correct
64 Correct 53 ms 2668 KB Output is correct
65 Correct 51 ms 2540 KB Output is correct
66 Correct 54 ms 2676 KB Output is correct
67 Correct 53 ms 2596 KB Output is correct
68 Correct 48 ms 2660 KB Output is correct
69 Correct 53 ms 2616 KB Output is correct
70 Correct 553 ms 16756 KB Output is correct
71 Correct 52 ms 2616 KB Output is correct
72 Correct 496 ms 16968 KB Output is correct
73 Correct 494 ms 16924 KB Output is correct
74 Correct 0 ms 204 KB Output is correct
75 Correct 0 ms 204 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 5 ms 972 KB Output is correct
80 Correct 579 ms 29868 KB Output is correct
81 Correct 576 ms 29852 KB Output is correct
82 Correct 541 ms 29952 KB Output is correct
83 Correct 543 ms 30032 KB Output is correct
84 Correct 549 ms 29856 KB Output is correct
85 Correct 538 ms 29840 KB Output is correct
86 Correct 161 ms 18512 KB Output is correct
87 Correct 0 ms 204 KB Output is correct