Submission #172126

# Submission time Handle Problem Language Result Execution time Memory
172126 2019-12-31T08:06:37 Z dennisstar Strange Device (APIO19_strange_device) C++11
100 / 100
596 ms 17040 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

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:15: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:20: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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 348 KB Output is correct
15 Correct 2 ms 296 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 61 ms 2584 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 256 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 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 348 KB Output is correct
5 Correct 441 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 525 ms 16956 KB Output is correct
3 Correct 525 ms 16976 KB Output is correct
4 Correct 523 ms 16856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 525 ms 16956 KB Output is correct
3 Correct 525 ms 16976 KB Output is correct
4 Correct 523 ms 16856 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 519 ms 16848 KB Output is correct
7 Correct 525 ms 16848 KB Output is correct
8 Correct 527 ms 16996 KB Output is correct
9 Correct 596 ms 16844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 525 ms 16956 KB Output is correct
3 Correct 525 ms 16976 KB Output is correct
4 Correct 523 ms 16856 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 52 ms 2536 KB Output is correct
7 Correct 54 ms 2540 KB Output is correct
8 Correct 54 ms 2536 KB Output is correct
9 Correct 55 ms 2536 KB Output is correct
10 Correct 53 ms 2440 KB Output is correct
11 Correct 55 ms 2536 KB Output is correct
12 Correct 52 ms 2536 KB Output is correct
13 Correct 64 ms 2536 KB Output is correct
14 Correct 54 ms 2540 KB Output is correct
15 Correct 59 ms 2536 KB Output is correct
16 Correct 56 ms 2540 KB Output is correct
17 Correct 57 ms 2540 KB Output is correct
18 Correct 519 ms 16848 KB Output is correct
19 Correct 505 ms 16928 KB Output is correct
20 Correct 594 ms 16976 KB Output is correct
21 Correct 57 ms 2540 KB Output is correct
22 Correct 51 ms 2536 KB Output is correct
23 Correct 201 ms 8668 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 57 ms 2508 KB Output is correct
4 Correct 580 ms 16848 KB Output is correct
5 Correct 57 ms 2536 KB Output is correct
6 Correct 57 ms 2496 KB Output is correct
7 Correct 57 ms 2540 KB Output is correct
8 Correct 57 ms 2536 KB Output is correct
9 Correct 56 ms 2536 KB Output is correct
10 Correct 56 ms 2540 KB Output is correct
11 Correct 57 ms 2472 KB Output is correct
12 Correct 51 ms 2536 KB Output is correct
13 Correct 57 ms 2540 KB Output is correct
14 Correct 565 ms 16848 KB Output is correct
15 Correct 57 ms 2536 KB Output is correct
16 Correct 514 ms 17040 KB Output is correct
17 Correct 504 ms 16848 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 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 348 KB Output is correct
15 Correct 2 ms 296 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 61 ms 2584 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 256 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 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 441 ms 16988 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 525 ms 16956 KB Output is correct
31 Correct 525 ms 16976 KB Output is correct
32 Correct 523 ms 16856 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 519 ms 16848 KB Output is correct
35 Correct 525 ms 16848 KB Output is correct
36 Correct 527 ms 16996 KB Output is correct
37 Correct 596 ms 16844 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 52 ms 2536 KB Output is correct
40 Correct 54 ms 2540 KB Output is correct
41 Correct 54 ms 2536 KB Output is correct
42 Correct 55 ms 2536 KB Output is correct
43 Correct 53 ms 2440 KB Output is correct
44 Correct 55 ms 2536 KB Output is correct
45 Correct 52 ms 2536 KB Output is correct
46 Correct 64 ms 2536 KB Output is correct
47 Correct 54 ms 2540 KB Output is correct
48 Correct 59 ms 2536 KB Output is correct
49 Correct 56 ms 2540 KB Output is correct
50 Correct 57 ms 2540 KB Output is correct
51 Correct 519 ms 16848 KB Output is correct
52 Correct 505 ms 16928 KB Output is correct
53 Correct 594 ms 16976 KB Output is correct
54 Correct 57 ms 2540 KB Output is correct
55 Correct 51 ms 2536 KB Output is correct
56 Correct 201 ms 8668 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 57 ms 2540 KB Output is correct
59 Correct 57 ms 2508 KB Output is correct
60 Correct 580 ms 16848 KB Output is correct
61 Correct 57 ms 2536 KB Output is correct
62 Correct 57 ms 2496 KB Output is correct
63 Correct 57 ms 2540 KB Output is correct
64 Correct 57 ms 2536 KB Output is correct
65 Correct 56 ms 2536 KB Output is correct
66 Correct 56 ms 2540 KB Output is correct
67 Correct 57 ms 2472 KB Output is correct
68 Correct 51 ms 2536 KB Output is correct
69 Correct 57 ms 2540 KB Output is correct
70 Correct 565 ms 16848 KB Output is correct
71 Correct 57 ms 2536 KB Output is correct
72 Correct 514 ms 17040 KB Output is correct
73 Correct 504 ms 16848 KB Output is correct
74 Correct 2 ms 256 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 376 KB Output is correct
79 Correct 7 ms 760 KB Output is correct
80 Correct 581 ms 16952 KB Output is correct
81 Correct 583 ms 16848 KB Output is correct
82 Correct 570 ms 16852 KB Output is correct
83 Correct 567 ms 16848 KB Output is correct
84 Correct 580 ms 16900 KB Output is correct
85 Correct 593 ms 16848 KB Output is correct
86 Correct 202 ms 8800 KB Output is correct
87 Correct 2 ms 252 KB Output is correct