Submission #231112

# Submission time Handle Problem Language Result Execution time Memory
231112 2020-05-12T19:00:27 Z ChrisT Strange Device (APIO19_strange_device) C++17
100 / 100
606 ms 41368 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define lc ind<<1
#define rc ind<<1|1
const int MN = 25e4+4, MOD = 1e9+7, BASE = 31;
int main () {
	int n; ll a,b;
	scanf ("%d %lld %lld",&n,&a,&b);
	ll x = a/__gcd(a,b+1);
	__int128 pp = (__int128)b*x;
	ll p = (ll)min(pp,__int128(1e18+2));
	vector<pll> segs;
	while (n--) {
		ll l,r;
		scanf ("%lld %lld",&l,&r); if (r-l+1 >= p) return !printf ("%lld\n",p);
		ll nxt = (l/p+1)*p;
		if (nxt <= r) {
			segs.emplace_back(l%p,(nxt-1)%p); segs.emplace_back(nxt%p,r%p);
		} else segs.emplace_back(l%p,r%p);
	}
	sort(all(segs));
	ll lr = -2; ll ret = 0;
	for (auto &[l,r] : segs) {
		if (r > lr) {
			ret += r-max(lr+1,l)+1;
			lr = r;
		}
	}
	printf ("%lld\n",ret);
	return 0;
}
/*
find period:
find first t>0 s/t t%b==0 && (t+t/b)%a==0
since b|t let t = xb for some minimal x
(xb+xb/b)%a == 0
(xb+x)%a==0
(x(b+1))%a==0
b+1 is constant, cancel out gcd(a,b+1)
x = a/gcd(a,b+1)
t = ba/gcd(a,b+1)
*/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:18:8: 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:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld %lld",&l,&r); if (r-l+1 >= p) return !printf ("%lld\n",p);
   ~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 10 ms 1024 KB Output is correct
3 Correct 10 ms 1024 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 59 ms 5744 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 450 ms 41368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 522 ms 24788 KB Output is correct
3 Correct 545 ms 30800 KB Output is correct
4 Correct 539 ms 30804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 522 ms 24788 KB Output is correct
3 Correct 545 ms 30800 KB Output is correct
4 Correct 539 ms 30804 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 516 ms 30904 KB Output is correct
7 Correct 558 ms 30804 KB Output is correct
8 Correct 531 ms 30928 KB Output is correct
9 Correct 586 ms 30740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 522 ms 24788 KB Output is correct
3 Correct 545 ms 30800 KB Output is correct
4 Correct 539 ms 30804 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 57 ms 5864 KB Output is correct
7 Correct 59 ms 5736 KB Output is correct
8 Correct 60 ms 5736 KB Output is correct
9 Correct 57 ms 5752 KB Output is correct
10 Correct 60 ms 5732 KB Output is correct
11 Correct 60 ms 5736 KB Output is correct
12 Correct 54 ms 5740 KB Output is correct
13 Correct 58 ms 5744 KB Output is correct
14 Correct 56 ms 5736 KB Output is correct
15 Correct 61 ms 5656 KB Output is correct
16 Correct 59 ms 5736 KB Output is correct
17 Correct 61 ms 5736 KB Output is correct
18 Correct 521 ms 30672 KB Output is correct
19 Correct 522 ms 30944 KB Output is correct
20 Correct 551 ms 30800 KB Output is correct
21 Correct 64 ms 5864 KB Output is correct
22 Correct 52 ms 5736 KB Output is correct
23 Correct 202 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 59 ms 5736 KB Output is correct
3 Correct 58 ms 5736 KB Output is correct
4 Correct 573 ms 30800 KB Output is correct
5 Correct 67 ms 5732 KB Output is correct
6 Correct 59 ms 6016 KB Output is correct
7 Correct 57 ms 5736 KB Output is correct
8 Correct 69 ms 5736 KB Output is correct
9 Correct 59 ms 5736 KB Output is correct
10 Correct 57 ms 5688 KB Output is correct
11 Correct 60 ms 5736 KB Output is correct
12 Correct 50 ms 5732 KB Output is correct
13 Correct 66 ms 6008 KB Output is correct
14 Correct 559 ms 30672 KB Output is correct
15 Correct 66 ms 5736 KB Output is correct
16 Correct 527 ms 30992 KB Output is correct
17 Correct 530 ms 30800 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 10 ms 1024 KB Output is correct
3 Correct 10 ms 1024 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 59 ms 5744 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 4 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 450 ms 41368 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 522 ms 24788 KB Output is correct
31 Correct 545 ms 30800 KB Output is correct
32 Correct 539 ms 30804 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 516 ms 30904 KB Output is correct
35 Correct 558 ms 30804 KB Output is correct
36 Correct 531 ms 30928 KB Output is correct
37 Correct 586 ms 30740 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 57 ms 5864 KB Output is correct
40 Correct 59 ms 5736 KB Output is correct
41 Correct 60 ms 5736 KB Output is correct
42 Correct 57 ms 5752 KB Output is correct
43 Correct 60 ms 5732 KB Output is correct
44 Correct 60 ms 5736 KB Output is correct
45 Correct 54 ms 5740 KB Output is correct
46 Correct 58 ms 5744 KB Output is correct
47 Correct 56 ms 5736 KB Output is correct
48 Correct 61 ms 5656 KB Output is correct
49 Correct 59 ms 5736 KB Output is correct
50 Correct 61 ms 5736 KB Output is correct
51 Correct 521 ms 30672 KB Output is correct
52 Correct 522 ms 30944 KB Output is correct
53 Correct 551 ms 30800 KB Output is correct
54 Correct 64 ms 5864 KB Output is correct
55 Correct 52 ms 5736 KB Output is correct
56 Correct 202 ms 18524 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 59 ms 5736 KB Output is correct
59 Correct 58 ms 5736 KB Output is correct
60 Correct 573 ms 30800 KB Output is correct
61 Correct 67 ms 5732 KB Output is correct
62 Correct 59 ms 6016 KB Output is correct
63 Correct 57 ms 5736 KB Output is correct
64 Correct 69 ms 5736 KB Output is correct
65 Correct 59 ms 5736 KB Output is correct
66 Correct 57 ms 5688 KB Output is correct
67 Correct 60 ms 5736 KB Output is correct
68 Correct 50 ms 5732 KB Output is correct
69 Correct 66 ms 6008 KB Output is correct
70 Correct 559 ms 30672 KB Output is correct
71 Correct 66 ms 5736 KB Output is correct
72 Correct 527 ms 30992 KB Output is correct
73 Correct 530 ms 30800 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 4 ms 256 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 4 ms 256 KB Output is correct
79 Correct 9 ms 1024 KB Output is correct
80 Correct 571 ms 30800 KB Output is correct
81 Correct 606 ms 30800 KB Output is correct
82 Correct 597 ms 30800 KB Output is correct
83 Correct 559 ms 30804 KB Output is correct
84 Correct 562 ms 30800 KB Output is correct
85 Correct 566 ms 30928 KB Output is correct
86 Correct 202 ms 18524 KB Output is correct
87 Correct 5 ms 384 KB Output is correct