답안 #519328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519328 2022-01-26T07:59:48 Z tibinyte 이상한 기계 (APIO19_strange_device) C++14
100 / 100
771 ms 64708 KB
#include <bits/stdc++.h>
using namespace std;
bool will_overflow(long long a, long long b) {
	long long c = a * b;
	if (a != c / b) {
		return true;
	}
	return false;
}
long long gcd(long long a, long long b) {
	while (b) {
		long long c = a % b;
		a = b;
		b = c;
	}
	return a;
}
int main() {
	cin.tie(nullptr)->ios_base::sync_with_stdio(false);
	long long n, a, b;
	cin >> n >> a >> b;
	long long p = 0;
	if (log10((double)a / (double)gcd(b + 1, a)) + log10(b) >= 18) {
		p = 1e18 + 1;
	}
	else {
		p = a / gcd(a, b + 1) * b;
	}
	map<long long, long long> wh;
	auto update = [&](long long st, long long dr) {
		wh[st]++;
		wh[dr + 1]--;
	};
	wh[p - 1] = 0;
	wh[0] = 0;
	for (long long i = 1; i <= n; ++i) {
		long long st, dr;
		cin >> st >> dr;
		long long lg = (dr - st) + 1;
		st %= p;
		if (st + lg - 1 < p) {
			update(st, st + lg - 1);
		}
		else {
			update(st, p - 1);
			lg -= (p - st);
			st = 0;
			if (st + lg - 1 < p) {
				update(st, st + lg - 1);
			}
			else {
				cout << p << '\n';
				return 0;
			}
		}
	}
	long long ans = 0;
	long long s = 0;
	for (map<long long, long long>::iterator i = wh.begin(); i != prev(wh.end()); ++i) {
		s += i->second;
		long long st = i->first, dr = next(i)->first - 1;
		if (s) {
			ans += dr - st + 1;
		}
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 1200 KB Output is correct
3 Correct 6 ms 1208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 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 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1228 KB Output is correct
17 Correct 74 ms 8404 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 236 ms 1120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 641 ms 63652 KB Output is correct
3 Correct 694 ms 63608 KB Output is correct
4 Correct 727 ms 63716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 641 ms 63652 KB Output is correct
3 Correct 694 ms 63608 KB Output is correct
4 Correct 727 ms 63716 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 679 ms 63612 KB Output is correct
7 Correct 692 ms 63672 KB Output is correct
8 Correct 651 ms 63616 KB Output is correct
9 Correct 731 ms 63572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 641 ms 63652 KB Output is correct
3 Correct 694 ms 63608 KB Output is correct
4 Correct 727 ms 63716 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 61 ms 8480 KB Output is correct
7 Correct 56 ms 8516 KB Output is correct
8 Correct 60 ms 8428 KB Output is correct
9 Correct 80 ms 8436 KB Output is correct
10 Correct 55 ms 8472 KB Output is correct
11 Correct 61 ms 8468 KB Output is correct
12 Correct 80 ms 8496 KB Output is correct
13 Correct 72 ms 8452 KB Output is correct
14 Correct 58 ms 8484 KB Output is correct
15 Correct 72 ms 8500 KB Output is correct
16 Correct 70 ms 8516 KB Output is correct
17 Correct 69 ms 8456 KB Output is correct
18 Correct 645 ms 63616 KB Output is correct
19 Correct 691 ms 63492 KB Output is correct
20 Correct 705 ms 63584 KB Output is correct
21 Correct 61 ms 8516 KB Output is correct
22 Correct 66 ms 8400 KB Output is correct
23 Correct 112 ms 3296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 67 ms 8516 KB Output is correct
3 Correct 66 ms 8476 KB Output is correct
4 Correct 730 ms 64708 KB Output is correct
5 Correct 65 ms 8520 KB Output is correct
6 Correct 65 ms 8420 KB Output is correct
7 Correct 80 ms 8424 KB Output is correct
8 Correct 78 ms 8492 KB Output is correct
9 Correct 65 ms 8492 KB Output is correct
10 Correct 61 ms 8428 KB Output is correct
11 Correct 68 ms 8384 KB Output is correct
12 Correct 67 ms 8240 KB Output is correct
13 Correct 74 ms 8320 KB Output is correct
14 Correct 741 ms 63888 KB Output is correct
15 Correct 57 ms 8324 KB Output is correct
16 Correct 660 ms 63948 KB Output is correct
17 Correct 673 ms 63904 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 1200 KB Output is correct
3 Correct 6 ms 1208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 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 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1228 KB Output is correct
17 Correct 74 ms 8404 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 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 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 236 ms 1120 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 641 ms 63652 KB Output is correct
31 Correct 694 ms 63608 KB Output is correct
32 Correct 727 ms 63716 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 679 ms 63612 KB Output is correct
35 Correct 692 ms 63672 KB Output is correct
36 Correct 651 ms 63616 KB Output is correct
37 Correct 731 ms 63572 KB Output is correct
38 Correct 0 ms 308 KB Output is correct
39 Correct 61 ms 8480 KB Output is correct
40 Correct 56 ms 8516 KB Output is correct
41 Correct 60 ms 8428 KB Output is correct
42 Correct 80 ms 8436 KB Output is correct
43 Correct 55 ms 8472 KB Output is correct
44 Correct 61 ms 8468 KB Output is correct
45 Correct 80 ms 8496 KB Output is correct
46 Correct 72 ms 8452 KB Output is correct
47 Correct 58 ms 8484 KB Output is correct
48 Correct 72 ms 8500 KB Output is correct
49 Correct 70 ms 8516 KB Output is correct
50 Correct 69 ms 8456 KB Output is correct
51 Correct 645 ms 63616 KB Output is correct
52 Correct 691 ms 63492 KB Output is correct
53 Correct 705 ms 63584 KB Output is correct
54 Correct 61 ms 8516 KB Output is correct
55 Correct 66 ms 8400 KB Output is correct
56 Correct 112 ms 3296 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 67 ms 8516 KB Output is correct
59 Correct 66 ms 8476 KB Output is correct
60 Correct 730 ms 64708 KB Output is correct
61 Correct 65 ms 8520 KB Output is correct
62 Correct 65 ms 8420 KB Output is correct
63 Correct 80 ms 8424 KB Output is correct
64 Correct 78 ms 8492 KB Output is correct
65 Correct 65 ms 8492 KB Output is correct
66 Correct 61 ms 8428 KB Output is correct
67 Correct 68 ms 8384 KB Output is correct
68 Correct 67 ms 8240 KB Output is correct
69 Correct 74 ms 8320 KB Output is correct
70 Correct 741 ms 63888 KB Output is correct
71 Correct 57 ms 8324 KB Output is correct
72 Correct 660 ms 63948 KB Output is correct
73 Correct 673 ms 63904 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 0 ms 204 KB Output is correct
76 Correct 1 ms 256 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 1 ms 296 KB Output is correct
79 Correct 8 ms 1220 KB Output is correct
80 Correct 771 ms 63936 KB Output is correct
81 Correct 691 ms 64012 KB Output is correct
82 Correct 712 ms 64008 KB Output is correct
83 Correct 740 ms 64060 KB Output is correct
84 Correct 723 ms 63944 KB Output is correct
85 Correct 681 ms 63852 KB Output is correct
86 Correct 115 ms 11524 KB Output is correct
87 Correct 1 ms 204 KB Output is correct