# 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(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);
}
}
else 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;
}
}
signed main() {
jess;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |