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<iostream>
using namespace std;
int t[200000];
int mod=1e6+7;
long long dp[2][200000];
int maxx[200000];
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>t[i];
for(int i=1;i<=n;i++)
dp[0][i]=1;
long long wynik=1;
for(int i=1;i<=n;i++)
maxx[i]=max(maxx[i-1],t[i]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
dp[i%2][j]=(j*dp[(i-1)%2][j]+dp[(i-1)%2][j+1])%mod;
wynik+=(t[n-i+1]-1)*dp[(i-1)%2][maxx[n-i]];
wynik%=mod;
}
cout<<wynik;
return 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... |
# | 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... |