Submission #948850

#TimeUsernameProblemLanguageResultExecution timeMemory
948850IrateModsum (NOI12_modsum)C++14
0 / 25
1 ms600 KiB
#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; 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); } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...