#include <iostream>
using namespace std;
const int stala=1e4+10;
const long long mod=1000007;
long long dp[stala][2];
long long dp2[stala][2];
int tab[stala];
void prep(int ile)
{
for(int i=1;i<=ile;i++){
dp[i][1]=dp[i][0];
dp2[i][1]=dp2[i][0];
dp[i][0]=0;
dp2[i][0]=0;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
cin>>ile;
for(int i=1;i<=ile;i++){
cin>>tab[i];
}
long long wyn=0;
for(int i=ile;i>=1;i--){
if(i==ile){
for(int j=1;j<=ile;j++){
dp[j][0]=j;
dp2[j][0]=1;
}
}
else{
for(int j=1;j<=i;j++){
dp[j][0]=(long long)j*(dp[j][1]+dp2[j+1][1]);
dp2[j][0]=dp[j][1]+dp2[j+1][1];
dp[j][0]%=mod;
dp[j][1]%=mod;
}
}
wyn+=dp[tab[i]-1][0];
wyn%=mod;
prep(i);
}
wyn++;
wyn%=mod;
cout<<wyn;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
183 ms |
784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |