Submission #255084

# Submission time Handle Problem Language Result Execution time Memory
255084 2020-07-31T08:39:38 Z BamiTorabi Strange Device (APIO19_strange_device) C++14
100 / 100
553 ms 36600 KB
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e6 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int cnt = 0, len = 0;
pll P[maxN], Q[maxN];

ll gcd(ll a, ll b){
	return (b == 0 ? a : gcd(b, a % b));
}

pll I(pll X, pll Y){
	pll Z;
	Z.first = max(X.first, Y.first);
	Z.second = min(X.second, Y.second);
	if (Z.first > Z.second)
		Z = {-1, -1};
	return Z;
}

pll U(pll X, pll Y){
	pll Z;
	Z.first = min(X.first, Y.first);
	Z.second = max(X.second, Y.second);
	return Z;
}

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; ll A, B; scanf("%d%lld%lld", &n, &A, &B);
	ll g = gcd(A, B + 1);
	ll L = (B / g <= INF / A ? A * B / g : INF);
	while (n--){
		ll l, r; scanf("%lld%lld", &l, &r);
		if (L <= (r - l + 1))
			return printf("%lld\n", L), 0;
		if (l >= L)
			l %= L;
		if (r >= L)
			r %= L;
		if (r >= l)
			P[cnt++] = {l, r};
		else{
			P[cnt++] = {l, L - 1};
			P[cnt++] = {0, r};
		}
	}
	sort(P, P + cnt);
	Q[0] = P[0];
	for (int i = 1; i < cnt; i++){
		if (I(Q[len], P[i]).first == -1)
			Q[++len] = P[i];
		else
			Q[len] = U(Q[len], P[i]);
	}
	ll ans = len + 1;
	for (int i = 0; i <= len; i++)
		ans += Q[i].second - Q[i].first;
	printf("%lld\n", ans);
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:57:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; ll A, B; scanf("%d%lld%lld", &n, &A, &B);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:61:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll l, r; scanf("%lld%lld", &l, &r);
            ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 54 ms 7160 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 386 ms 16228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 506 ms 36600 KB Output is correct
3 Correct 465 ms 36472 KB Output is correct
4 Correct 476 ms 35064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 506 ms 36600 KB Output is correct
3 Correct 465 ms 36472 KB Output is correct
4 Correct 476 ms 35064 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 469 ms 35064 KB Output is correct
7 Correct 503 ms 35064 KB Output is correct
8 Correct 489 ms 35140 KB Output is correct
9 Correct 515 ms 35028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 506 ms 36600 KB Output is correct
3 Correct 465 ms 36472 KB Output is correct
4 Correct 476 ms 35064 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 48 ms 5112 KB Output is correct
7 Correct 50 ms 5112 KB Output is correct
8 Correct 47 ms 5092 KB Output is correct
9 Correct 47 ms 5112 KB Output is correct
10 Correct 47 ms 5112 KB Output is correct
11 Correct 50 ms 5112 KB Output is correct
12 Correct 47 ms 5112 KB Output is correct
13 Correct 49 ms 5240 KB Output is correct
14 Correct 47 ms 5112 KB Output is correct
15 Correct 51 ms 5112 KB Output is correct
16 Correct 53 ms 7160 KB Output is correct
17 Correct 50 ms 7160 KB Output is correct
18 Correct 490 ms 32280 KB Output is correct
19 Correct 447 ms 32324 KB Output is correct
20 Correct 536 ms 32248 KB Output is correct
21 Correct 50 ms 7160 KB Output is correct
22 Correct 46 ms 7160 KB Output is correct
23 Correct 180 ms 14200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 52 ms 5880 KB Output is correct
3 Correct 51 ms 5880 KB Output is correct
4 Correct 526 ms 36600 KB Output is correct
5 Correct 50 ms 5880 KB Output is correct
6 Correct 51 ms 5880 KB Output is correct
7 Correct 48 ms 5880 KB Output is correct
8 Correct 51 ms 5880 KB Output is correct
9 Correct 60 ms 5880 KB Output is correct
10 Correct 49 ms 5880 KB Output is correct
11 Correct 54 ms 5884 KB Output is correct
12 Correct 48 ms 5880 KB Output is correct
13 Correct 65 ms 5880 KB Output is correct
14 Correct 549 ms 36568 KB Output is correct
15 Correct 51 ms 7032 KB Output is correct
16 Correct 494 ms 32120 KB Output is correct
17 Correct 507 ms 32120 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 6 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 54 ms 7160 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 386 ms 16228 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 506 ms 36600 KB Output is correct
31 Correct 465 ms 36472 KB Output is correct
32 Correct 476 ms 35064 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 469 ms 35064 KB Output is correct
35 Correct 503 ms 35064 KB Output is correct
36 Correct 489 ms 35140 KB Output is correct
37 Correct 515 ms 35028 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 48 ms 5112 KB Output is correct
40 Correct 50 ms 5112 KB Output is correct
41 Correct 47 ms 5092 KB Output is correct
42 Correct 47 ms 5112 KB Output is correct
43 Correct 47 ms 5112 KB Output is correct
44 Correct 50 ms 5112 KB Output is correct
45 Correct 47 ms 5112 KB Output is correct
46 Correct 49 ms 5240 KB Output is correct
47 Correct 47 ms 5112 KB Output is correct
48 Correct 51 ms 5112 KB Output is correct
49 Correct 53 ms 7160 KB Output is correct
50 Correct 50 ms 7160 KB Output is correct
51 Correct 490 ms 32280 KB Output is correct
52 Correct 447 ms 32324 KB Output is correct
53 Correct 536 ms 32248 KB Output is correct
54 Correct 50 ms 7160 KB Output is correct
55 Correct 46 ms 7160 KB Output is correct
56 Correct 180 ms 14200 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 52 ms 5880 KB Output is correct
59 Correct 51 ms 5880 KB Output is correct
60 Correct 526 ms 36600 KB Output is correct
61 Correct 50 ms 5880 KB Output is correct
62 Correct 51 ms 5880 KB Output is correct
63 Correct 48 ms 5880 KB Output is correct
64 Correct 51 ms 5880 KB Output is correct
65 Correct 60 ms 5880 KB Output is correct
66 Correct 49 ms 5880 KB Output is correct
67 Correct 54 ms 5884 KB Output is correct
68 Correct 48 ms 5880 KB Output is correct
69 Correct 65 ms 5880 KB Output is correct
70 Correct 549 ms 36568 KB Output is correct
71 Correct 51 ms 7032 KB Output is correct
72 Correct 494 ms 32120 KB Output is correct
73 Correct 507 ms 32120 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 5 ms 1024 KB Output is correct
80 Correct 553 ms 32248 KB Output is correct
81 Correct 530 ms 32244 KB Output is correct
82 Correct 506 ms 32248 KB Output is correct
83 Correct 501 ms 32120 KB Output is correct
84 Correct 500 ms 32236 KB Output is correct
85 Correct 512 ms 32280 KB Output is correct
86 Correct 186 ms 13432 KB Output is correct
87 Correct 1 ms 384 KB Output is correct