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;
signed main() {
#define ll long long
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n;cin >> n;
vector<pair<int,int>> inp(n);
for(auto &e : inp)
cin >> e.first >> e.second;
// We can solve this problem by finding the number of sums with k mod 5
vector<array<int,5>> dp(n);
vector<array<int,5>> count(n,{0,0,0,0,0});
for(int i =0 ;i<n;i++){
for(int j = inp[i].first;j<=inp[i].second;j++){
count[i][(j%5)]++;
}
}
// Calculating dp[0];
for(int a1 = 0;a1<5;a1++)
dp[0][a1] = count[0][a1];
for(int i = 1;i<n;i++){
dp[i] = {0,0,0,0,0};
for(int al = 0;al<5;al++){
for(int bl = 0;bl<5;bl++){
dp[i][(al + bl)%5] += dp[i - 1][al]*count[i][bl];
}
}
}
ll ans = 0;
for(int al = 0;al<5;al++){
if(al == 0)
ans += dp[n - 1][al];
else if(al == 1 || al == 4)
ans += 4*dp[n - 1][al];
else
ans += 5*dp[n - 1][al];
}
cout << ans << "\n";
}
# | 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... |