#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
int mod=1000007;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int it[n];
for(int i=0;i<n;i++){
cin>>it[i];
}
int pre[n];
pre[0]=it[0];
for(int i=1;i<n;i++){
pre[i]=max(pre[i-1],it[i]);
}
int dp[n];
for(int i=0;i<n;i++){
dp[i]=1;
}
int tot=0;
for(int i=n-1;i>=0;i--){
int dp2[n];
if(it[i]<pre[i]){
tot+=(dp[pre[i]-1]*(pre[i]-it[i]));
}
if(i>0 and pre[i-1]<n){
if(it[i]!=pre[i-1]+1){
tot+=dp[pre[i]];
}
}
tot%=mod;
for(int j=0;j<n;j++){
if(i==n-1){
dp2[j]=1;
}
else{
dp2[j]=(dp[j]*(j+1));
if(j<n-1){
dp2[j]+=dp[j+1];
}
dp2[j]%=mod;
}
}
for(int j=0;j<n;j++){
dp[j]=dp2[j];
}
/* cout<<tot<<endl;
for(int j=0;j<n;j++){
cout<<dp[j]<<" ";
}
cout<<endl;*/
if(i==0){
tot=(dp[0]-tot+mod)%mod;
}
}
cout<<tot<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
758 ms |
568 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
195 ms |
484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
768 ms |
536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |