Submission #934545

# Submission time Handle Problem Language Result Execution time Memory
934545 2024-02-27T14:32:58 Z ByeWorld Strange Device (APIO19_strange_device) C++14
100 / 100
1172 ms 53412 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define ll long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
const ll INF = 1e18;

int n, a, b;
int F, K, P;
vector <pii> vec;
int ans;

signed main() {
	cin >> n >> a >> b;
	b++;
    F = __gcd(a, b);
    a /= F;
    if (INF/b < a) K = INF;
    else K = a * b;
    P = K - a;
    
    for(int i=1; i<=n; i++){
        int l, r; cin >> l >> r;
        if(r-l+1 >= P){
            cout << P << '\n'; exit(0);
        }
        l %= P; r %= P;
        if(l<=r){
            vec.pb({l, r});
        } else {
            vec.pb({l, P-1}); 
            vec.pb({0, r});
        }
    }
    sort(vec.begin(), vec.end());
    int las = -1, ans = 0;
    for(auto in : vec){
        if(in.se <= las) continue;
        ans += in.se - max(in.fi-1, las);
        las = in.se;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 1080 KB Output is correct
3 Correct 16 ms 1052 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 14 ms 1116 KB Output is correct
17 Correct 134 ms 5212 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 763 ms 35444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1130 ms 44404 KB Output is correct
3 Correct 1139 ms 44996 KB Output is correct
4 Correct 1041 ms 45188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1130 ms 44404 KB Output is correct
3 Correct 1139 ms 44996 KB Output is correct
4 Correct 1041 ms 45188 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1052 ms 44576 KB Output is correct
7 Correct 1068 ms 35432 KB Output is correct
8 Correct 1091 ms 35240 KB Output is correct
9 Correct 1068 ms 35068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1130 ms 44404 KB Output is correct
3 Correct 1139 ms 44996 KB Output is correct
4 Correct 1041 ms 45188 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 110 ms 4644 KB Output is correct
7 Correct 107 ms 4600 KB Output is correct
8 Correct 101 ms 4548 KB Output is correct
9 Correct 107 ms 4548 KB Output is correct
10 Correct 107 ms 4640 KB Output is correct
11 Correct 106 ms 4424 KB Output is correct
12 Correct 105 ms 4548 KB Output is correct
13 Correct 106 ms 4476 KB Output is correct
14 Correct 107 ms 4432 KB Output is correct
15 Correct 105 ms 4552 KB Output is correct
16 Correct 126 ms 4524 KB Output is correct
17 Correct 106 ms 4524 KB Output is correct
18 Correct 1041 ms 35736 KB Output is correct
19 Correct 1061 ms 35128 KB Output is correct
20 Correct 1056 ms 35388 KB Output is correct
21 Correct 111 ms 4632 KB Output is correct
22 Correct 101 ms 4388 KB Output is correct
23 Correct 345 ms 15312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 104 ms 4432 KB Output is correct
3 Correct 150 ms 4572 KB Output is correct
4 Correct 1132 ms 35688 KB Output is correct
5 Correct 124 ms 4392 KB Output is correct
6 Correct 103 ms 4296 KB Output is correct
7 Correct 108 ms 4568 KB Output is correct
8 Correct 109 ms 4228 KB Output is correct
9 Correct 109 ms 4284 KB Output is correct
10 Correct 110 ms 4552 KB Output is correct
11 Correct 108 ms 4292 KB Output is correct
12 Correct 104 ms 4548 KB Output is correct
13 Correct 109 ms 4496 KB Output is correct
14 Correct 1096 ms 40344 KB Output is correct
15 Correct 110 ms 5140 KB Output is correct
16 Correct 1091 ms 44480 KB Output is correct
17 Correct 1042 ms 44436 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 1080 KB Output is correct
3 Correct 16 ms 1052 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 14 ms 1116 KB Output is correct
17 Correct 134 ms 5212 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 488 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 763 ms 35444 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1130 ms 44404 KB Output is correct
31 Correct 1139 ms 44996 KB Output is correct
32 Correct 1041 ms 45188 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1052 ms 44576 KB Output is correct
35 Correct 1068 ms 35432 KB Output is correct
36 Correct 1091 ms 35240 KB Output is correct
37 Correct 1068 ms 35068 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 110 ms 4644 KB Output is correct
40 Correct 107 ms 4600 KB Output is correct
41 Correct 101 ms 4548 KB Output is correct
42 Correct 107 ms 4548 KB Output is correct
43 Correct 107 ms 4640 KB Output is correct
44 Correct 106 ms 4424 KB Output is correct
45 Correct 105 ms 4548 KB Output is correct
46 Correct 106 ms 4476 KB Output is correct
47 Correct 107 ms 4432 KB Output is correct
48 Correct 105 ms 4552 KB Output is correct
49 Correct 126 ms 4524 KB Output is correct
50 Correct 106 ms 4524 KB Output is correct
51 Correct 1041 ms 35736 KB Output is correct
52 Correct 1061 ms 35128 KB Output is correct
53 Correct 1056 ms 35388 KB Output is correct
54 Correct 111 ms 4632 KB Output is correct
55 Correct 101 ms 4388 KB Output is correct
56 Correct 345 ms 15312 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 104 ms 4432 KB Output is correct
59 Correct 150 ms 4572 KB Output is correct
60 Correct 1132 ms 35688 KB Output is correct
61 Correct 124 ms 4392 KB Output is correct
62 Correct 103 ms 4296 KB Output is correct
63 Correct 108 ms 4568 KB Output is correct
64 Correct 109 ms 4228 KB Output is correct
65 Correct 109 ms 4284 KB Output is correct
66 Correct 110 ms 4552 KB Output is correct
67 Correct 108 ms 4292 KB Output is correct
68 Correct 104 ms 4548 KB Output is correct
69 Correct 109 ms 4496 KB Output is correct
70 Correct 1096 ms 40344 KB Output is correct
71 Correct 110 ms 5140 KB Output is correct
72 Correct 1091 ms 44480 KB Output is correct
73 Correct 1042 ms 44436 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 436 KB Output is correct
79 Correct 10 ms 1024 KB Output is correct
80 Correct 1073 ms 53236 KB Output is correct
81 Correct 1172 ms 53292 KB Output is correct
82 Correct 1106 ms 53308 KB Output is correct
83 Correct 1040 ms 53188 KB Output is correct
84 Correct 1063 ms 53412 KB Output is correct
85 Correct 1085 ms 53172 KB Output is correct
86 Correct 348 ms 20020 KB Output is correct
87 Correct 0 ms 344 KB Output is correct