#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
int gcd(int a,int b){
while (b) b^=a^=b^=a%=b;
return a;
}
signed main(){
int n,a,b;
cin>>n>>a>>b;
pair <int,int> p[n];
for (int i=0; i<n; i++) cin>>p[i].x>>p[i].y;
if (n==1){
int f=p[0].y-p[0].x+1;
int s=a/gcd(a,b+1);
int op=min(f,s);
cout<<op<<endl;
} else {
set <pair <int,int> > s;
for (int i=0; i<n; i++){
for (int t=p[i].x; t<=p[i].y; t++) s.insert({(t+t/b)%a,t%b});
}
cout<<s.size()<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
60 ms |
12908 KB |
Output is correct |
3 |
Correct |
84 ms |
18412 KB |
Output is correct |
4 |
Correct |
2 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
8 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
44 ms |
7020 KB |
Output is correct |
16 |
Correct |
42 ms |
7276 KB |
Output is correct |
17 |
Correct |
170 ms |
10112 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
144 ms |
32364 KB |
Output is correct |
3 |
Correct |
194 ms |
32056 KB |
Output is correct |
4 |
Correct |
135 ms |
30648 KB |
Output is correct |
5 |
Execution timed out |
5079 ms |
78316 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1605 ms |
78728 KB |
Output is correct |
3 |
Runtime error |
3458 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1605 ms |
78728 KB |
Output is correct |
3 |
Runtime error |
3458 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1605 ms |
78728 KB |
Output is correct |
3 |
Runtime error |
3458 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
1870 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
60 ms |
12908 KB |
Output is correct |
3 |
Correct |
84 ms |
18412 KB |
Output is correct |
4 |
Correct |
2 ms |
876 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
8 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
44 ms |
7020 KB |
Output is correct |
16 |
Correct |
42 ms |
7276 KB |
Output is correct |
17 |
Correct |
170 ms |
10112 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |