#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
vector<pair<long long,long long>>v;
cin>>n;
for(long long i=0;i<n;i++)
{
long long x,y;
cin>>x>>y;
v.push_back({x,y});
}
long long dp[n][5];
memset(dp,0,sizeof dp);
for(long long i=v[0].first;i<=v[0].second;i++)
{
dp[0][i%5]++;
}
for(long long i=1;i<n;i++)
{
for(long long mod=0;mod<5;mod++)
{
for(long long j=v[i].first;j<=v[i].second;j++)
{
dp[i][(mod+j)%5]+=dp[i-1][mod];
}
}
}
/*for(long long i=0;i<n;i++)
{
for(long long mod=0;mod<5;mod++)
{
cout<<dp[i][mod]<<" ";
}
cout<<endl;
}*/
cout<<4*(dp[n-1][1]+dp[n-1][4])+5*(dp[n-1][2]+dp[n-1][3])+dp[n-1][0]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 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 |
348 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 |