#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 |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
659 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
468 KB |
Output is correct |
2 |
Correct |
163 ms |
468 KB |
Output is correct |
3 |
Correct |
164 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
678 ms |
564 KB |
Output is correct |
2 |
Correct |
681 ms |
596 KB |
Output is correct |
3 |
Correct |
680 ms |
616 KB |
Output is correct |