#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005;
pair<int, int> ranges[mxN];
int dp[mxN][5], n;
int f(int indx, int mod){
if(indx == n)return (mod * mod % 5) * (mod * mod + 2) % 5 + 1;
if(dp[indx][mod] != -1)return dp[indx][mod];
int res = 0;
for(int i = 0;i < 5;++i){
int cnt = 0;
cnt = (ranges[indx].second - i) / 5;
if(ranges[indx].first - i - 1 > 0)cnt -= (ranges[indx].first - i - 1) / 5;
for(int j = ranges[indx].first - i;j <= min(0, ranges[indx].second - i);++j){
cnt += (j % 5 == 0);
}
if(cnt)res += cnt * f(indx + 1, (mod + i) % 5);
}
return dp[indx][mod] = res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0;i < n;++i){
cin >> ranges[i].first >> ranges[i].second;
}
for(int i = 0;i < mxN;++i){
for(int j = 0;j < 5;++j){
dp[i][j] = -1;
}
}
cout << f(0, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |