This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |