# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
# define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, a, b;
pii r[1000005];
int ten(int x) {
int ret=0;
while(x>1) {
x/=10;
ret++;
}
return ret;
}
void solve() {
cin >> n >> a >> b;
int sum=0;
bool st=1;
for(int i=1; i<=n; i++) {
cin >> r[i].fi >> r[i].se;
if((1e18-sum)<(r[i].se-r[i].fi+1)) st=0;
if(st) sum+=(r[i].se - r[i].fi + 1);
}
if(sum<=1e6) {
set<pii> s;
for(int i=1; i<=n; i++) {
for(int j=r[i].fi; j<=r[i].se; j++) {
int c=j + (j/b);
int x=c%a;
int y=j%b;
// cout << "idx " << i << " " << j << " : " << x << " " << y << endl;
s.insert({x, y});
}
}
cout << s.size() << endl;
}
else if(n==1) {
if(ten(a)+ten(b)>=18) {
cout << r[1].se - r[1].fi + 1 << endl;
} else {
cout << max(0LL, min(a*b-1, r[1].se) - r[1].fi + 1);
}
}
}
signed main() {
jess;
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
33 ms |
12496 KB |
Output is correct |
3 |
Correct |
51 ms |
18072 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
340 KB |
Output is correct |
15 |
Correct |
41 ms |
7220 KB |
Output is correct |
16 |
Correct |
20 ms |
6848 KB |
Output is correct |
17 |
Correct |
42 ms |
8184 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
108 ms |
32184 KB |
Output is correct |
3 |
Correct |
173 ms |
32100 KB |
Output is correct |
4 |
Correct |
93 ms |
30604 KB |
Output is correct |
5 |
Incorrect |
187 ms |
16488 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
233 ms |
15908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
233 ms |
15908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
233 ms |
15908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
24 ms |
1824 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
33 ms |
12496 KB |
Output is correct |
3 |
Correct |
51 ms |
18072 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 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 |
340 KB |
Output is correct |
15 |
Correct |
41 ms |
7220 KB |
Output is correct |
16 |
Correct |
20 ms |
6848 KB |
Output is correct |
17 |
Correct |
42 ms |
8184 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
256 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
108 ms |
32184 KB |
Output is correct |
26 |
Correct |
173 ms |
32100 KB |
Output is correct |
27 |
Correct |
93 ms |
30604 KB |
Output is correct |
28 |
Incorrect |
187 ms |
16488 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |