Submission #569544

# Submission time Handle Problem Language Result Execution time Memory
569544 2022-05-27T13:35:26 Z Trunkty Strange Device (APIO19_strange_device) C++14
100 / 100
901 ms 100232 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

#define DEBUG
#ifdef DEBUG
  #define debug(x) cout << #x << ": " << x << endl
#else
  #define debug(x)
#endif

ll inf = 2e18;
ll n,a,b,p;
map<ll,ll> mp;
ll bef,curr,ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a >> b;
	ll gc = __gcd(a,b+1LL);
	if(a/gc>inf/b){
		p = 1e18;
	}
	else{
		p = a/gc*b;
	}
	for(ll i=1;i<=n;i++){
		ll c,d;
		cin >> c >> d;
		if(d-c+1LL>=p){
			cout << p << "\n";
			return 0;
		}
		else{
			c %= p;
			d %= p;
			if(c<=d){
				mp[c]++;
				mp[d+1LL]--;
			}
			else{
				mp[0]++;
				mp[d+1LL]--;
				mp[c]++;
				mp[p]--;
			}
		}
	}
	for(auto it=mp.begin();it!=mp.end();it++){
		if(curr){
			ans += it->first-bef;
		}
		bef = it->first;
		curr += it->second;
	}
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 1228 KB Output is correct
3 Correct 7 ms 1224 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 63 ms 10236 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 274 ms 25372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 684 ms 78408 KB Output is correct
3 Correct 726 ms 82068 KB Output is correct
4 Correct 777 ms 78412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 684 ms 78408 KB Output is correct
3 Correct 726 ms 82068 KB Output is correct
4 Correct 777 ms 78412 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 731 ms 77128 KB Output is correct
7 Correct 862 ms 77460 KB Output is correct
8 Correct 814 ms 76656 KB Output is correct
9 Correct 901 ms 77828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 684 ms 78408 KB Output is correct
3 Correct 726 ms 82068 KB Output is correct
4 Correct 777 ms 78412 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 59 ms 10184 KB Output is correct
7 Correct 60 ms 10272 KB Output is correct
8 Correct 66 ms 10180 KB Output is correct
9 Correct 69 ms 10316 KB Output is correct
10 Correct 64 ms 10296 KB Output is correct
11 Correct 56 ms 10328 KB Output is correct
12 Correct 58 ms 10224 KB Output is correct
13 Correct 67 ms 10244 KB Output is correct
14 Correct 56 ms 10284 KB Output is correct
15 Correct 70 ms 10188 KB Output is correct
16 Correct 67 ms 10312 KB Output is correct
17 Correct 67 ms 10256 KB Output is correct
18 Correct 650 ms 76732 KB Output is correct
19 Correct 690 ms 82196 KB Output is correct
20 Correct 751 ms 79756 KB Output is correct
21 Correct 63 ms 10188 KB Output is correct
22 Correct 62 ms 10216 KB Output is correct
23 Correct 117 ms 10788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 67 ms 10188 KB Output is correct
3 Correct 68 ms 10272 KB Output is correct
4 Correct 712 ms 83520 KB Output is correct
5 Correct 70 ms 10176 KB Output is correct
6 Correct 66 ms 10232 KB Output is correct
7 Correct 66 ms 10172 KB Output is correct
8 Correct 64 ms 10188 KB Output is correct
9 Correct 64 ms 10204 KB Output is correct
10 Correct 61 ms 10180 KB Output is correct
11 Correct 62 ms 10188 KB Output is correct
12 Correct 58 ms 10176 KB Output is correct
13 Correct 69 ms 10184 KB Output is correct
14 Correct 790 ms 100068 KB Output is correct
15 Correct 57 ms 10188 KB Output is correct
16 Correct 671 ms 99976 KB Output is correct
17 Correct 652 ms 99948 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 1228 KB Output is correct
3 Correct 7 ms 1224 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 63 ms 10236 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 274 ms 25372 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 684 ms 78408 KB Output is correct
31 Correct 726 ms 82068 KB Output is correct
32 Correct 777 ms 78412 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 731 ms 77128 KB Output is correct
35 Correct 862 ms 77460 KB Output is correct
36 Correct 814 ms 76656 KB Output is correct
37 Correct 901 ms 77828 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 59 ms 10184 KB Output is correct
40 Correct 60 ms 10272 KB Output is correct
41 Correct 66 ms 10180 KB Output is correct
42 Correct 69 ms 10316 KB Output is correct
43 Correct 64 ms 10296 KB Output is correct
44 Correct 56 ms 10328 KB Output is correct
45 Correct 58 ms 10224 KB Output is correct
46 Correct 67 ms 10244 KB Output is correct
47 Correct 56 ms 10284 KB Output is correct
48 Correct 70 ms 10188 KB Output is correct
49 Correct 67 ms 10312 KB Output is correct
50 Correct 67 ms 10256 KB Output is correct
51 Correct 650 ms 76732 KB Output is correct
52 Correct 690 ms 82196 KB Output is correct
53 Correct 751 ms 79756 KB Output is correct
54 Correct 63 ms 10188 KB Output is correct
55 Correct 62 ms 10216 KB Output is correct
56 Correct 117 ms 10788 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 67 ms 10188 KB Output is correct
59 Correct 68 ms 10272 KB Output is correct
60 Correct 712 ms 83520 KB Output is correct
61 Correct 70 ms 10176 KB Output is correct
62 Correct 66 ms 10232 KB Output is correct
63 Correct 66 ms 10172 KB Output is correct
64 Correct 64 ms 10188 KB Output is correct
65 Correct 64 ms 10204 KB Output is correct
66 Correct 61 ms 10180 KB Output is correct
67 Correct 62 ms 10188 KB Output is correct
68 Correct 58 ms 10176 KB Output is correct
69 Correct 69 ms 10184 KB Output is correct
70 Correct 790 ms 100068 KB Output is correct
71 Correct 57 ms 10188 KB Output is correct
72 Correct 671 ms 99976 KB Output is correct
73 Correct 652 ms 99948 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 6 ms 1272 KB Output is correct
80 Correct 720 ms 100024 KB Output is correct
81 Correct 735 ms 100000 KB Output is correct
82 Correct 783 ms 99992 KB Output is correct
83 Correct 771 ms 100096 KB Output is correct
84 Correct 745 ms 100232 KB Output is correct
85 Correct 714 ms 100104 KB Output is correct
86 Correct 115 ms 12824 KB Output is correct
87 Correct 1 ms 212 KB Output is correct