/* Will you ever win? */
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=10005;
const long long mod=1000*1000+7;
long long c[2][nmax],bell[nmax],mx[nmax],pw[nmax];
long long ans;
int v[nmax];
int n,i,j,use;
int main()
{
// freopen("data.in","r",stdin);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
mx[i]=max(mx[i-1],1LL*v[i]);
}
bell[0]=1;
ans=v[n]-1;c[0][0]=1;
for(i=1;i<n;i++)
{
use=1-use;
c[use][0]=1;
for(j=1;j<=i;j++)
{
c[use][j]=(c[1-use][j]+c[1-use][j-1])%mod;
}
pw[0]=v[n-i]-1;
for(j=1;j<=i;j++)
pw[j]=(1LL*pw[j-1]*mx[n-i-1])%mod;
for(j=0;j<i;j++)
{
bell[i]=(1LL*bell[i]+(bell[j]*c[1-use][j]))%mod;
}
for(j=0;j<=i;j++)
ans=(ans+1LL*((bell[i-j]*c[use][j])%mod)*pw[j])%mod;
}
cout<<(ans+1)%mod;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
624 KB |
Output is correct |
2 |
Correct |
2 ms |
624 KB |
Output is correct |
3 |
Correct |
3 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
736 KB |
Output is correct |
2 |
Correct |
12 ms |
736 KB |
Output is correct |
3 |
Correct |
13 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
971 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
1276 KB |
Output is correct |
2 |
Correct |
292 ms |
1276 KB |
Output is correct |
3 |
Correct |
313 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1024 ms |
1276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |