Submission #172125

# Submission time Handle Problem Language Result Execution time Memory
172125 2019-12-31T08:03:13 Z dennisstar Strange Device (APIO19_strange_device) C++11
100 / 100
609 ms 36600 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

vector<pll> V;
const ll INF=(1e18)+10;
int n; ll A, B;
ll l, r;

int main() {
	scanf("%d %lld %lld", &n, &A, &B);
	A/=__gcd(A, B+1);
	if ((ll)(1e18)/B<A) A=INF;
	else A*=B;
	for (int i=0; i<n; i++) {
		scanf("%lld %lld", &l, &r);
		if (r-l+1>=A) V.push_back({0, A-1});
		else {
			r=(r-l)+l%A;
			l%=A;
			if (r>=A) {
				V.push_back({l, A-1});
				V.push_back({0, r-A});
			}
			else V.push_back({l, r});
		}
	}
	ll mx=0, ans=0; sort(all(V));
	for (pll pl:V) {
		ans+=max(0ll, pl.se-max(pl.fi, mx)+1);
		mx=max(pl.se+1, mx);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  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]
   scanf("%lld %lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 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 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 59 ms 2540 KB Output is correct
18 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 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 441 ms 16948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 528 ms 16904 KB Output is correct
3 Correct 523 ms 19016 KB Output is correct
4 Correct 526 ms 25408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 528 ms 16904 KB Output is correct
3 Correct 523 ms 19016 KB Output is correct
4 Correct 526 ms 25408 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 531 ms 33088 KB Output is correct
7 Correct 537 ms 35040 KB Output is correct
8 Correct 532 ms 36120 KB Output is correct
9 Correct 594 ms 36600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 528 ms 16904 KB Output is correct
3 Correct 523 ms 19016 KB Output is correct
4 Correct 526 ms 25408 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 53 ms 5732 KB Output is correct
7 Correct 56 ms 5484 KB Output is correct
8 Correct 52 ms 5732 KB Output is correct
9 Correct 56 ms 5576 KB Output is correct
10 Correct 53 ms 5732 KB Output is correct
11 Correct 56 ms 5228 KB Output is correct
12 Correct 53 ms 5732 KB Output is correct
13 Correct 59 ms 5348 KB Output is correct
14 Correct 53 ms 5684 KB Output is correct
15 Correct 62 ms 5732 KB Output is correct
16 Correct 60 ms 5732 KB Output is correct
17 Correct 70 ms 5736 KB Output is correct
18 Correct 525 ms 35024 KB Output is correct
19 Correct 509 ms 35128 KB Output is correct
20 Correct 599 ms 34748 KB Output is correct
21 Correct 57 ms 5736 KB Output is correct
22 Correct 52 ms 5732 KB Output is correct
23 Correct 201 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 57 ms 2540 KB Output is correct
3 Correct 56 ms 2536 KB Output is correct
4 Correct 585 ms 20068 KB Output is correct
5 Correct 57 ms 4092 KB Output is correct
6 Correct 57 ms 5096 KB Output is correct
7 Correct 57 ms 5280 KB Output is correct
8 Correct 59 ms 3940 KB Output is correct
9 Correct 56 ms 5092 KB Output is correct
10 Correct 58 ms 3940 KB Output is correct
11 Correct 59 ms 4720 KB Output is correct
12 Correct 52 ms 5348 KB Output is correct
13 Correct 58 ms 5220 KB Output is correct
14 Correct 567 ms 24188 KB Output is correct
15 Correct 58 ms 5220 KB Output is correct
16 Correct 518 ms 34152 KB Output is correct
17 Correct 509 ms 35536 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 7 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 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 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 59 ms 2540 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 441 ms 16948 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 528 ms 16904 KB Output is correct
31 Correct 523 ms 19016 KB Output is correct
32 Correct 526 ms 25408 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 531 ms 33088 KB Output is correct
35 Correct 537 ms 35040 KB Output is correct
36 Correct 532 ms 36120 KB Output is correct
37 Correct 594 ms 36600 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 53 ms 5732 KB Output is correct
40 Correct 56 ms 5484 KB Output is correct
41 Correct 52 ms 5732 KB Output is correct
42 Correct 56 ms 5576 KB Output is correct
43 Correct 53 ms 5732 KB Output is correct
44 Correct 56 ms 5228 KB Output is correct
45 Correct 53 ms 5732 KB Output is correct
46 Correct 59 ms 5348 KB Output is correct
47 Correct 53 ms 5684 KB Output is correct
48 Correct 62 ms 5732 KB Output is correct
49 Correct 60 ms 5732 KB Output is correct
50 Correct 70 ms 5736 KB Output is correct
51 Correct 525 ms 35024 KB Output is correct
52 Correct 509 ms 35128 KB Output is correct
53 Correct 599 ms 34748 KB Output is correct
54 Correct 57 ms 5736 KB Output is correct
55 Correct 52 ms 5732 KB Output is correct
56 Correct 201 ms 18512 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 57 ms 2540 KB Output is correct
59 Correct 56 ms 2536 KB Output is correct
60 Correct 585 ms 20068 KB Output is correct
61 Correct 57 ms 4092 KB Output is correct
62 Correct 57 ms 5096 KB Output is correct
63 Correct 57 ms 5280 KB Output is correct
64 Correct 59 ms 3940 KB Output is correct
65 Correct 56 ms 5092 KB Output is correct
66 Correct 58 ms 3940 KB Output is correct
67 Correct 59 ms 4720 KB Output is correct
68 Correct 52 ms 5348 KB Output is correct
69 Correct 58 ms 5220 KB Output is correct
70 Correct 567 ms 24188 KB Output is correct
71 Correct 58 ms 5220 KB Output is correct
72 Correct 518 ms 34152 KB Output is correct
73 Correct 509 ms 35536 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 256 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 7 ms 1016 KB Output is correct
80 Correct 597 ms 32460 KB Output is correct
81 Correct 586 ms 31016 KB Output is correct
82 Correct 591 ms 30672 KB Output is correct
83 Correct 571 ms 30376 KB Output is correct
84 Correct 574 ms 30000 KB Output is correct
85 Correct 609 ms 27600 KB Output is correct
86 Correct 204 ms 18524 KB Output is correct
87 Correct 2 ms 256 KB Output is correct