#include<iostream>
using namespace std;
int a[10000],N,x[10000];
typedef long long ll;
ll d[2][10001];//given at nth position (implicit, reverse) and cutoff index (starts at 0): # of possibilities?
const int md=1e9+7,ans=0;
int main(){
cin>>N;
for(int i=0;i<N;++i)cin>>a[i];
int u=0,ans=0;
for(int i=0;i<N;++i){
x[i]=u=max(u,a[i]);
}
for(int i=0;i<=N;++i){
d[N%2][i]=1;
}
for(int i=N-1;i>=0;--i){
for(int j=0;j<=i;++j){
d[i%2][j]=(d[(i+1)%2][j+1]+d[(i+1)%2][j]*j)%md;
}
if(i==N-1){
ans+=(d[i%2][a[i]-1]);
}else{
ans+=(d[(i+1)%2][x[i]-1]*(a[i]-1));
}
ans%=md;
//cout<<ans<<endl;
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
628 KB |
Output is correct |
6 |
Correct |
2 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
628 KB |
Output is correct |
2 |
Correct |
2 ms |
628 KB |
Output is correct |
3 |
Correct |
2 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
112 ms |
944 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
110 ms |
1012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |