/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
const long long INF = 5e18 + 7;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;
int lcm(int a, int b){
int ans = a / __gcd(a, b);
if (INF / ans < b){
return INF;
}
return ans * b;
}
int calperiod(int A, int B){
/*for(int i = 1; i <= 1000; ++i){
if ((i + i / B) % A == 0 && i % B == 0) return i;
}*/
//lcm(B + 1, A)...
int g = lcm(B + 1, A);
if (g == INF) return INF;
return (g / (B + 1)) * B;
}
void solve()
{
int n, A, B; cin >> n >> A >> B;
int g = calperiod(A, B);
vector <pair<int, int>> range;
for(int i = 1; i <= n; ++i){
int x, y; cin >> x >> y;
if (x - y >= g){
cout << g << endl;
return;
}
x %= g; y %= g;
if (x <= y) range.push_back({x, y});
else{
range.push_back({x, g - 1});
range.push_back({0, y});
}
}
sort(range.begin(), range.end());
int ans = range[0].second - range[0].first + 1;
int r = range[0].second;
for(int i = 1; i < (int)range.size(); ++i){
if (range[i].second > r){
if (range[i].first > r){
ans += range[i].second - range[i].first + 1;
} else {
ans += range[i].second - r;
}
r = range[i].second;
}
}
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("codeforces.inp","r",stdin);
// freopen("codeforces.out","w",stdout);
int t = 1; // cin >> t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
988 KB |
Output is correct |
3 |
Correct |
6 ms |
1064 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
43 ms |
5636 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
316 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
300 ms |
41216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
53116 KB |
Output is correct |
3 |
Correct |
411 ms |
50900 KB |
Output is correct |
4 |
Correct |
393 ms |
51196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
53116 KB |
Output is correct |
3 |
Correct |
411 ms |
50900 KB |
Output is correct |
4 |
Correct |
393 ms |
51196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
413 ms |
51044 KB |
Output is correct |
7 |
Correct |
401 ms |
53204 KB |
Output is correct |
8 |
Correct |
427 ms |
53300 KB |
Output is correct |
9 |
Correct |
450 ms |
48732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
53116 KB |
Output is correct |
3 |
Correct |
411 ms |
50900 KB |
Output is correct |
4 |
Correct |
393 ms |
51196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
38 ms |
5696 KB |
Output is correct |
7 |
Correct |
42 ms |
5684 KB |
Output is correct |
8 |
Correct |
38 ms |
5612 KB |
Output is correct |
9 |
Correct |
40 ms |
5652 KB |
Output is correct |
10 |
Correct |
43 ms |
5672 KB |
Output is correct |
11 |
Correct |
42 ms |
5644 KB |
Output is correct |
12 |
Correct |
38 ms |
5708 KB |
Output is correct |
13 |
Correct |
41 ms |
5684 KB |
Output is correct |
14 |
Correct |
40 ms |
5648 KB |
Output is correct |
15 |
Correct |
47 ms |
5696 KB |
Output is correct |
16 |
Correct |
42 ms |
5628 KB |
Output is correct |
17 |
Correct |
40 ms |
5608 KB |
Output is correct |
18 |
Correct |
435 ms |
49220 KB |
Output is correct |
19 |
Correct |
420 ms |
50096 KB |
Output is correct |
20 |
Correct |
456 ms |
50012 KB |
Output is correct |
21 |
Correct |
45 ms |
5700 KB |
Output is correct |
22 |
Correct |
37 ms |
5676 KB |
Output is correct |
23 |
Correct |
130 ms |
18444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
44 ms |
5640 KB |
Output is correct |
3 |
Correct |
47 ms |
5692 KB |
Output is correct |
4 |
Correct |
480 ms |
47640 KB |
Output is correct |
5 |
Correct |
44 ms |
5696 KB |
Output is correct |
6 |
Correct |
42 ms |
5660 KB |
Output is correct |
7 |
Correct |
43 ms |
5700 KB |
Output is correct |
8 |
Correct |
44 ms |
5704 KB |
Output is correct |
9 |
Correct |
42 ms |
5696 KB |
Output is correct |
10 |
Correct |
51 ms |
5688 KB |
Output is correct |
11 |
Correct |
44 ms |
5872 KB |
Output is correct |
12 |
Correct |
39 ms |
5740 KB |
Output is correct |
13 |
Correct |
42 ms |
5696 KB |
Output is correct |
14 |
Correct |
459 ms |
53132 KB |
Output is correct |
15 |
Correct |
41 ms |
5700 KB |
Output is correct |
16 |
Correct |
433 ms |
53172 KB |
Output is correct |
17 |
Correct |
405 ms |
36868 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
988 KB |
Output is correct |
3 |
Correct |
6 ms |
1064 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
43 ms |
5636 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
316 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |