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>
#define MOD 1000007
using namespace std;
long long sum,v[100005],n,i,maxi,din[2][100005],inainte,acum,j,din2[1000005],ceau[1000005];
int main()
{
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n;
for (i=1;i<=n;i++)
{
cin>>v[i];
}
maxi=0;
for (i=1;i<=n;i++)
{
ceau[n-i]=maxi;
maxi=max(maxi,v[i]);
}
for (i=0;i<=n+5;i++)
{
din[0][i]=1;
}
din2[0]=1;
for (i=1;i<=n;i++)
{
inainte=1-i%2;
acum=i%2;
for (j=0;j<=n+5;j++)
{
din[acum][j]=((j*din[inainte][j])%MOD+din[inainte][j+1])%MOD;
if (j==ceau[i])
{
din2[i]=din[acum][j];
}
}
}
maxi=0;
for (i=1;i<=n;i++)
{
sum=(sum+((v[i]-1)*din2[n-i])%MOD)%MOD;
maxi=max(maxi,v[i]);
}
cout<<sum+1;
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... |