답안 #984786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984786 2024-05-17T05:32:52 Z Tsagana 이상한 기계 (APIO19_strange_device) C++14
100 / 100
383 ms 71772 KB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pi pair<int, int >
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mset multiset
#define F first
#define S second

using namespace std;

const int INF = 1e18;
int n, A, B, s;
int l[1000001];
int r[1000001];

int gcd(int a, int b) {return (a == 0 ? b : gcd(b % a, a));}
void solve ()
{
	cin >> n >> A >> B;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		s += r[i] - l[i] + 1;
	}
	map<int, int> cnt;
	if  (INF / A < (B + 1) / gcd(B + 1, A)) {return void(cout << s);}
	int cyc = A / gcd(A, B + 1) * B;
	vector<pair<int, int>> range;
	for (int i = 0; i < n; i++) {
		if (r[i] - l[i] + 1 >= cyc) {return void(cout << cyc);}
		if ((l[i] %= cyc) <= (r[i] %= cyc)) {range.pb({l[i], r[i]});}
		else {range.pb({l[i], cyc - 1}); range.pb({0, r[i]});}
	} sort(all(range));
	int ans = range[0].S - range[0].F + 1, pre = range[0].S;
	for (int i = 1; i < range.size(); i++) {
		if (range[i].S > pre) {
			ans += range[i].S - max(range[i].F, pre + 1) + 1;
			pre = range[i].S;
		}
	}
	cout << ans;
}
signed main(){IOS solve(); return 0;}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:41:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 1; i < range.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 4 ms 3140 KB Output is correct
3 Correct 4 ms 3164 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 4 ms 3164 KB Output is correct
17 Correct 36 ms 12504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 233 ms 57820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 323 ms 71640 KB Output is correct
3 Correct 306 ms 70484 KB Output is correct
4 Correct 302 ms 70424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 323 ms 71640 KB Output is correct
3 Correct 306 ms 70484 KB Output is correct
4 Correct 302 ms 70424 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 325 ms 70096 KB Output is correct
7 Correct 323 ms 71508 KB Output is correct
8 Correct 332 ms 71388 KB Output is correct
9 Correct 351 ms 69840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 323 ms 71640 KB Output is correct
3 Correct 306 ms 70484 KB Output is correct
4 Correct 302 ms 70424 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 33 ms 12480 KB Output is correct
7 Correct 41 ms 12640 KB Output is correct
8 Correct 32 ms 12504 KB Output is correct
9 Correct 35 ms 12504 KB Output is correct
10 Correct 33 ms 12656 KB Output is correct
11 Correct 42 ms 12492 KB Output is correct
12 Correct 31 ms 12492 KB Output is correct
13 Correct 34 ms 12640 KB Output is correct
14 Correct 32 ms 12656 KB Output is correct
15 Correct 35 ms 12652 KB Output is correct
16 Correct 35 ms 12504 KB Output is correct
17 Correct 32 ms 12528 KB Output is correct
18 Correct 326 ms 71648 KB Output is correct
19 Correct 311 ms 70904 KB Output is correct
20 Correct 345 ms 70368 KB Output is correct
21 Correct 36 ms 12504 KB Output is correct
22 Correct 30 ms 12504 KB Output is correct
23 Correct 96 ms 32216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 35 ms 12652 KB Output is correct
3 Correct 34 ms 12496 KB Output is correct
4 Correct 358 ms 71528 KB Output is correct
5 Correct 40 ms 13008 KB Output is correct
6 Correct 35 ms 12504 KB Output is correct
7 Correct 33 ms 12504 KB Output is correct
8 Correct 35 ms 12492 KB Output is correct
9 Correct 35 ms 12496 KB Output is correct
10 Correct 36 ms 12512 KB Output is correct
11 Correct 36 ms 12748 KB Output is correct
12 Correct 30 ms 12676 KB Output is correct
13 Correct 35 ms 12656 KB Output is correct
14 Correct 369 ms 70756 KB Output is correct
15 Correct 35 ms 12492 KB Output is correct
16 Correct 319 ms 70748 KB Output is correct
17 Correct 318 ms 70196 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 4 ms 3140 KB Output is correct
3 Correct 4 ms 3164 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2512 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 4 ms 3164 KB Output is correct
17 Correct 36 ms 12504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 233 ms 57820 KB Output is correct
29 Correct 1 ms 2648 KB Output is correct
30 Correct 323 ms 71640 KB Output is correct
31 Correct 306 ms 70484 KB Output is correct
32 Correct 302 ms 70424 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 325 ms 70096 KB Output is correct
35 Correct 323 ms 71508 KB Output is correct
36 Correct 332 ms 71388 KB Output is correct
37 Correct 351 ms 69840 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 33 ms 12480 KB Output is correct
40 Correct 41 ms 12640 KB Output is correct
41 Correct 32 ms 12504 KB Output is correct
42 Correct 35 ms 12504 KB Output is correct
43 Correct 33 ms 12656 KB Output is correct
44 Correct 42 ms 12492 KB Output is correct
45 Correct 31 ms 12492 KB Output is correct
46 Correct 34 ms 12640 KB Output is correct
47 Correct 32 ms 12656 KB Output is correct
48 Correct 35 ms 12652 KB Output is correct
49 Correct 35 ms 12504 KB Output is correct
50 Correct 32 ms 12528 KB Output is correct
51 Correct 326 ms 71648 KB Output is correct
52 Correct 311 ms 70904 KB Output is correct
53 Correct 345 ms 70368 KB Output is correct
54 Correct 36 ms 12504 KB Output is correct
55 Correct 30 ms 12504 KB Output is correct
56 Correct 96 ms 32216 KB Output is correct
57 Correct 1 ms 2648 KB Output is correct
58 Correct 35 ms 12652 KB Output is correct
59 Correct 34 ms 12496 KB Output is correct
60 Correct 358 ms 71528 KB Output is correct
61 Correct 40 ms 13008 KB Output is correct
62 Correct 35 ms 12504 KB Output is correct
63 Correct 33 ms 12504 KB Output is correct
64 Correct 35 ms 12492 KB Output is correct
65 Correct 35 ms 12496 KB Output is correct
66 Correct 36 ms 12512 KB Output is correct
67 Correct 36 ms 12748 KB Output is correct
68 Correct 30 ms 12676 KB Output is correct
69 Correct 35 ms 12656 KB Output is correct
70 Correct 369 ms 70756 KB Output is correct
71 Correct 35 ms 12492 KB Output is correct
72 Correct 319 ms 70748 KB Output is correct
73 Correct 318 ms 70196 KB Output is correct
74 Correct 1 ms 2392 KB Output is correct
75 Correct 1 ms 2396 KB Output is correct
76 Correct 1 ms 2396 KB Output is correct
77 Correct 0 ms 2396 KB Output is correct
78 Correct 0 ms 2396 KB Output is correct
79 Correct 4 ms 3160 KB Output is correct
80 Correct 383 ms 70176 KB Output is correct
81 Correct 365 ms 70552 KB Output is correct
82 Correct 382 ms 71772 KB Output is correct
83 Correct 341 ms 71184 KB Output is correct
84 Correct 352 ms 70168 KB Output is correct
85 Correct 340 ms 71240 KB Output is correct
86 Correct 94 ms 33512 KB Output is correct
87 Correct 1 ms 2392 KB Output is correct